How do you match a regex in javascript? -


i'm trying match email regex \b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}\b string in javascript. @ moment i'm using code email.match(/b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}/) doesn't match email addresses. regex's need changed before used in javascript?

problems matching email addresses regex aside:

you have add case-insensitive modifier since matching uppercase characters. missing \ in front of b (which makes expression match b literally) , \b @ end (thanks @tomalak) (even though "work" without it):

email.match(/\b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}\b/i) 

if want know whether expressions matches or not, can use .test:

patter.test(email) 

more regular expressions in javascript.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -