Can someone help me convert this c# regular express (email validation) to Javascript?
@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
Can someone help me convert this c# regular express (email validation) to Javascript?
@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
It should work pretty much as is1:
var address = . . .;
var r = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (address.match(r)) {
// address is okay
}
1 That is, it should work in JavaScript as well as it does in C#. Email validation is actually quite complex and your C# regex is really not very good for this. See this thread.