Issue with common Regex for aplhabets and numbers -


i using following regex - [a-za-z0-9]{9,18} means can use alphabets , numbers minimum length 9 , maximum length 18. should not take special characters. takes values adv0098890 etc. taking adv0098890[], wrong.

how can prevent ?

your regex matching first part of string. try wrapping pattern in ^$:

>> !!('adv0098890'   =~ /[a-za-z0-9]{9,18}/) => true >> !!('adv0098890[]' =~ /[a-za-z0-9]{9,18}/) => true >> !!('adv0098890'   =~ /^[a-za-z0-9]{9,18}$/) => true >> !!('adv0098890[]' =~ /^[a-za-z0-9]{9,18}$/) => false 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -