Invalid regular expression: //^(+98|0098|98|0)?9d{9}$/g/: Nothing to repeat

I want to validate a regExp text by match function but I got this error message:

Invalid regular expression: //^(+98|0098|98|0)?9d{9}$/g/: Nothing to repeat

 if (event.target.value.match("/^(+98|0098|98|0)?9d{9}$/g")) {
..

Answer

Remove the quotes

if (event.target.value.match(/^(+98|0098|98|0)?9d{9}$/g))
 { ..

Leave a Reply

Your email address will not be published. Required fields are marked *