regex - Range out of order in character class in javascript -


i don't know because regex incorrect:

var domain = "google\.com\.br"; var reemail = new regexp("^([a-za-z0-9_\-\.])+\@" + domain + "$"); 

i need validate email, example: reemail.test("contact@google.com.br");

i error:

range out of order in character class

because create regexp using string _\-\. becomes _-. , invalid range. (it range _ . , not correct)

you need double escape it:

new regexp("^([a-za-z0-9_\\-\\.])+@" + domain + "$"); 

that way \\ becomes \ in string , used escape -in regexp.

edit:

if create regexp string helpful log result see if did right:

e.g. part of regexp

console.log("^([a-za-z0-9_\-\.])+\@"); 

results in:

^([a-za-z0-9_-.])+@ 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -