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? 

Edited by joe_john
Link to comment
Share on other sites

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. Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.