Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to validate an email using following:

var reg = /^\w+([-+.']\w+)*@@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;


but i dont want the email that starts with a digit.
what should i add in the above regex.
please help.
Posted
Comments
[no name] 7-Apr-15 7:09am    
start with a digit mean ?
Andy Lanng 7-Apr-15 7:16am    
/d is a digit in this case ([0-9])

If you want to exclude digit from the first letter, then put this at the front of your regex pattern,
^[^\d]

The first ^ means the start of the string, the second ^ in the square brackets means to exclude, \d means matching a digit.
Learn more: http://www.w3schools.com/jsref/jsref_obj_regexp.asp[^]
 
Share this answer
 
v4
Comments
dirtyshooter 8-Apr-15 5:57am    
no it dint work.
Peter Leow 8-Apr-15 6:43am    
In the first place, you original Regex for email is not correct. Check the demo here => https://regex101.com/r/nV2kM0/1
dirtyshooter 8-Apr-15 7:25am    
working for me. except for the conditions i want. can you suggest how shall i integrate your expression into mine.?
Peter Leow 8-Apr-15 7:30am    
What expression? You have only given one line of code that did not work. I have already provided the answer to your question. If you want to write the code, check out the various methods in the link that I have provided in Solution 1. I hereby considered this question answered.
Add \D to the front of the regex string: "\d" is a digit, \d is anything but a digit.

But more likely, you want to add [A-Za-z] instead, to restrict it to just an upper or lower case character.
 
Share this answer
 
Hi,

Write like this..

JavaScript
var reg = /^[a-z][a-zA-Z0-9_](.[a-zA-Z][a-zA-Z0-9_])?@[a-z][a-zA-Z-0-9]*.[a-z]+(.[a-z]+)?$/;


Demo : Exclude digit from email starting
 
Share this answer
 
Comments
dirtyshooter 8-Apr-15 7:38am    
thanks RajeeshMenoth. That helped.
dirtyshooter 8-Apr-15 7:42am    
but its working in jsfiddle only, not in my project.
[no name] 8-Apr-15 23:53pm    
k,it's working in jsfiddle.so you can add the jquery version latest in your project.check ur project i think some other issue will stop the working of jsfiddle code like juqery conflicts.it's working fine for my projects..pls check and clarify me Mr Abhinav2201.
dirtyshooter 9-Apr-15 4:51am    
the solution derived by me is working fine for me. Your logic helped. Thanks a lot.
[no name] 9-Apr-15 5:02am    
kk, no probs.my solution is working fine for me..
this worked perfectly. thanks everyone.

var reg = /^[a-z]+[a-zA-Z0-9]*([-+.']\w+)*@@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900