简体   繁体   中英

javascript regular expression to test e-mail

I am trying to check the e-amil address like abc@example.co.uk or a.bc@eyample.com etc

and I am using regular expression like

[a-zA-Z0-9\._]+@[^.]+[a.zA-Z]+\.[a-z{2,5}]+

Can someone suggest how to correct it?

Thank you

See Using a regular expression to validate an email address

and you can try :

[a-zA-Z0-9.!#$%&'*+-/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*

This should work

Example

var sEmail = txtEmail;

var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

if (filter.test(sEmail)) {
    return true;
}
else {
    return false;
}

If you make an input type email in new browsers it will validate to a certain level. It will only look for characters followed by a @ and than a few characters after it.

Validating is to catch user mistakes not to make it harder for users to fill in your form.

I want to replace apostrophes "'" with "/" from string.

for example: var str ="te'xt"; want output like this "te/xt"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM