I am using the following regex in my react-native app.
This is an email validation regex :
^[\w]+@((?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+)(?:[A-Za-z0-9-]{2,63}(?<!-))
This works fine in the browser but crashes the react native app due to the following :
no stack', reason: 'Unhandled JS Exception: Invalid regular expression: invalid group specifier name
Could someone please help getting this to work on react native, maybe by achieving the same thing that this regex achieves but without the lookbehind expression ?
The problem is likely caused the by the (?<!-) negative lookahead at the end of the regex pattern, which your JavaScript engine does not support. To ensure that a hyphen does not occur at the end of the email, we can simply use:
^[\w]+@((?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+)(?:[A-Za-z0-9-]{1,62}[A-Za-z0-9])
That is, just use [A-Za-z0-9] to represent the final of 63 possible characters in the pattern.
This regex will not work likely problem in regex pattern i think.
this works for me for simple email format abc@mail.com
var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;