Javascript regular expressions

linkaiyi
Follow

regular expressions in Javascript

var pattern = //
pattern.text(string) // test if string matches the pattern

username and email check

var pattern;
pattern = "/^[a-zA-Z0-9]{1,6}$/" // check if username hat 6 letters/digits

pattern = "/^/w+@/w+.(/w+)+$/" // check if email is correct simple version

function validateEmail(email) {
    const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(String(email).toLowerCase());
} // best version
Object has 0 attachments

Was this article helpful?

This article is viewed 15 times!

Recent Viewed Articles

0 Comments

Leave a Comment

Support