Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How do i prevent typing special characters in a field.

i tryed:
VB
NOT(REGEX(Phone,
"\\D*?(\\d\\D*?)"))


but then i cant put spaces in space should be allowed.

can anybody help me please?

Thank you
#regards
Seb.
Posted

You can use this regex:
PERL
/[\w ]+/

This will allow word characters and spaces.
 
Share this answer
 
A universal regex pattern for this task does not exists. It's set of reason[^].

Have a look here: http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7[^] and choose the proper one for you.
 
Share this answer
 
"\D" means "any character that isn't a digit", and "\d" means "any character that is a digit" so your regex is:
Any character that is not a digit, any number of repetitions, as few as possible
A numbered capture group. [\d\D*?]
    \d\D*?
        Any digit
        Any character that is not a digit, any number of repetitions, as few as possible

Which is a little odd for a phone number, which is what you appear to be trying to match - because it will match anything that has a digit in it...
The "normal" phone number regex is along the lines of:
\((?<areacode>\d{3})\)\s*(?<number>\d{3}(?:-|\s*)\d{4})</number></areacode>

And it might be worth your starting there and working out how to match exactly what you are after.

To help you in this, get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
It's where I got the explanation of your regex, and the sample phone number one from.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900