473,394 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Check string for special chars help

I wanted to include a string invalid character check in my application.
Like the field comment , if a user inserts any special characters
(Except '[' , ']' , '@' , '/' , '=' and numbers - alphabets) , the function should return true , if the string contains no special char in any position , the function should return false.

Can anyone design a function to check the special chars ?
Thanks so much.
May 9 '08 #1
2 12857
Markus
6,050 Expert 4TB
So, there HAS to be a special char in the string?
Ok, so, you can preg_match()

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $_string = "thisisagoodstring*";
  3. $_stringbad = "thisisabadstring";
  4.  
  5. if(preg_match('#[^a-zA-Z0-9]#', $_string))
  6. {
  7.     echo "special char found!";
  8. }
  9. ?>
  10.  
May 9 '08 #2
dlite922
1,584 Expert 1GB
I wanted to include a string invalid character check in my application.
Like the field comment , if a user inserts any special characters
(Except '[' , ']' , '@' , '/' , '=' and numbers - alphabets) , the function should return true , if the string contains no special char in any position , the function should return false.

Can anyone design a function to check the special chars ?
Thanks so much.
On your free time, I recommend looking into regular expressions. They will seam over-whelming at first and many sites will go deep into it, but learning the basics will help you alot.

In coding (your IDE's Find and Replace feature) AND in your code.

Have fun,


-Dan
May 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: wolfgang haefelinger | last post by:
Greetings, I'm trying to read (japanese) chars from a file. While doing so I encounter that a char with length 2 is returned. Is this to be expected or is there something wrong? Basically...
6
by: Jonas Meurer | last post by:
hello, my script selects a comment saved as VARCHAR in MySQL and displays it inside an html page. the problem is, that the comment contains several special characters, as mysterious utf-8...
0
by: Steffen Gebert | last post by:
Hello, I want to fetch the page via php from a mysql-db, which is called by an emulated filename (mod_rewrite, but that might be unimportant). So I have a file, which is called by guestbook.html...
2
by: Thorsten Viel | last post by:
Hi List, im trying to use special chars with the std::string (like S) but when i cout<< the string the special chars have disappeared. What's wrong here? Thanks in advance
4
by: dutch disCo | last post by:
Hi, I'm trying to use GET method to pass variables through my script files. Unfortunately, when a special char (&, ?, +) is being posted the variable gets trimmed in a very strange way. I'm...
9
by: Durgesh Sharma | last post by:
Hi All, Pleas help me .I am a starter as far as C Language is concerned . How can i Right Trim all the white spaces of a very long (2000 chars) Charecter string ( from the Right Side ) ? or how...
6
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time...
0
by: smith2 | last post by:
Hi, I have a string which has special chars coming in an input file. I want to set it in a wstring variable present in table . It is not setting the wstring variable if it has any special...
9
by: Petrosa | last post by:
Hi. i am new to java and just starting to learn how it works. My problem now is, i need a very simple code, that shows a window, where u enter a string, and by pressing a button, it runs various...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.