How to exclude the email address which has unicode characters using regular expression? I have an email address job.rajü@example.de I need to validate the email address and should accept only those email's which doesn't have unicode characters using regular expression.
Asked
Active
Viewed 1,174 times
2
-
Take a look at this: http://stackoverflow.com/questions/46155/validate-email-address-in-javascript – Jørgen Dec 08 '11 at 07:43
-
Why wouldn't you validate a valid email address? Anyway, note that there is no real way to **validate** an email address. The user can write a syntactically correct address that does not exist or a dummy email address (e.g. mailinator) which is valid and exists but is not his real address. – nico Dec 08 '11 at 07:43
-
4Every character in **job.rajü@example.de** is a Unicode character. Do you mean that you want to exclude non-ASCII characters? – Keith Thompson Dec 08 '11 at 07:49
-
1Just use [A-Za-z] wherever you want to match a letter. Simple as that. – FailedDev Dec 08 '11 at 07:56
-
What i am looking for is that.. suppose i have 10 email address and out of that two are there which contains the character ü, i need to show an error message for these two email address that you cannot have multi byte characters in the email address. – nimi Dec 08 '11 at 08:01
-
\A(\w|['])+([-+.](\w|['])+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* this is my current regular expression. – nimi Dec 08 '11 at 08:06
-
@FailedDev: `[A-Za-z]` excludes digits, which are perfectly valid in e-mail addresses. – Keith Thompson Dec 08 '11 at 08:24
-
@KeithThompson As I said, *put this wherever you want to match letter*. Last time I checked letter != digit. – FailedDev Dec 08 '11 at 08:27
-
@FailedDev: Ok -- but the OP didn't mention letters. I'm afraid I don't see the relevance of your comment. – Keith Thompson Dec 08 '11 at 08:30
-
1@KeithThompson I c what you mean. So [A-Za-z0-9] is what I meant I guess. – FailedDev Dec 08 '11 at 08:35
-
@nico, it sounds like you're confusing validation and verification. Validation would be checking to see whether the address in syntactically correct; whether an email address is 'real' or is nonexistant/a dummy is down to verification. – Jordan Wallwork Dec 08 '11 at 09:18
-
Voting to close as dupe. You should be validating e-mail addresses the "right" way. It is very tricky, so don't re-invent the wheel. Just use an existing JavaScript solution *and* validate it server-side with a real e-mail address validator. It is darn near impossible to fully validate all possible valid e-mail addresses using regex alone - they are much too complicated. – Merlyn Morgan-Graham Dec 08 '11 at 09:19
-
[This regex is fully compliant](http://ex-parrot.com/~pdw/Mail-RFC822-Address.html). But I wouldn't trust it to work. It is just the wrong language for the job. See http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses – Merlyn Morgan-Graham Dec 08 '11 at 09:21
-
@Jordan Wallwork: if you wish, I include existence of email address in the "validation" process. A matter of semantics. – nico Dec 08 '11 at 09:43
-
@FailedDev: `[A-Za-z0-9]` still excludes a number of characters that are perfectly valid in e-mail addresses. (It would reject mine, for example.) I think the syntax of valid e-mail addresses is more complex than you think it is; I'm fairly sure it's more complex than *I* think it is. 8-)} – Keith Thompson Dec 08 '11 at 20:53
-
I know that is more complex.. And as I said for nth time this should only be used where a ASCII "letter/digit" is involved. – FailedDev Dec 08 '11 at 20:55
1 Answers
1
If you want to accept any valid email address, I'd suggest taking a look at "Comparing E-mail Address Validating Regular Expressions." Here's the best email regex they have for matching all valid email addresses.
For JavaScript:
/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
I've created an example at JSBin of this in action in JavaScript:

calvinf
- 3,754
- 3
- 28
- 41
-
So you just copy a regex from a site, which you don't even know what it does and paste it here? I think If I flip a coin I will have more chances.. – FailedDev Dec 08 '11 at 08:23
-
I've used these regex before. If you want full details about how they work, read the site. I pasted it here for easier access and in case the site ever goes offline. – calvinf Dec 08 '11 at 08:42
-
I've added a JSBin example and tested to verify that the JavaScript regex does not accept the unicode characters I tested. – calvinf Dec 08 '11 at 09:07
-