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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -