Jump to content

block certain words using validation regex


joe_john

Recommended Posts

This is kind of related to the question from yesterday, on how to block urls in the phone number field 

 

I was given this code:

 

 

/^([\d\.()\:\- ]+)(ext(ension)?:\s+\d+)?$/i

 

which is good, but it's not liberal enough. I looked at past submissions, and people are entering some weird things. for example, instead of extension, they entered @ext  which would get rejected if I implement the above code. 

 

my goal is to be as liberal as possible, so I think instead of allowing certain characters and disallowing everything else, I should allow everything and disallow just certain characters

 

I want to block

http  

//

www

 .com  

.net

.info

.org

 

if someone puts any of these strings in the phone number field and presses submit, the form should not get submitted. 

 

Can I do this? 

Except for the extensions, the basic rule would be "digits, symbols, and spaces", right? Then the extension might have "e" or "ext" or "extension" or whatever, followed by more numbers.

^[\d.-() ]+([extension]+\d+)$
Doesn't allow slashes, doesn't allow letters not found in the word "extension" and even those have to be followed by just digits.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.