简体   繁体   中英

validate email without allowing spaces in jquery

I want to make email field without allowing spaces. I alread gave reg like the following

@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$

Here how to add without spaces.. Help Me....

This will do it in Jquery;

var email=('#myemailfield').val();//email field
var email_exp= /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/;

if (!email.match(email_exp)){ return Alert('Please, enter a valid E-mail to continue');}

Hope it helps

Try this.......

var regexp = /^[a-zA-Z0-9-_]+$/;  
var check = "Sunil";    
if (check.search(regexp) == -1)    
{ alert('invalid'); }     
else      
{ alert('valid'); }   

hope this will help you.

User this regular expression this will help you.

/^([a-zA-Z0-9_\\.\\-])+\\@((a-zA-Z0-9-]+\\.)+([a-zA-Z0-9][2,4])+$/;

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