-2

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})(\]?)$
KenD
  • 5,280
  • 7
  • 48
  • 85
user2324030
  • 11
  • 1
  • 2

1 Answers1

0

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.

Community
  • 1
  • 1
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521