I found a regex at regexlib and I want to use it in a simple string validation using javascript.
The regex is:
^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
But I tried to use it like this:
mystring = '[email protected]';
re = '^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$';
if(mystring.match(re)){
console.log('true');
}
And I got this console error:
Uncaught SyntaxError: Invalid regular expression: //^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$/: Range out of order in character class
What's wrong? I'm not a professional.. This is just a simple project I'm trying to do in my free time.