0

I have to implement a regex pattern in angular 8 application that only can restrict @ ,-,=,+ at the starting(0 index)of any string and can use as may as time we want if first character is not @,-,=,+.

I have create regex pattern = ^[A-Za-z0-9$&,:;?#|' <>.^()%!(/)(\)(])([){}$~_]+[A-Za-z0-9$&+,:;=?@#|' <>.^*()%!(\-)(\/)(\\)(\])(\[){}*$~_]*$

which is working fine in https://regex101.com/.

For ex: &jvjdjkfdkjkjd not restricted

    sdsdas@-+++=         not restricted

    -jgjjdj              restricted

    =fjkdfjjd            restricted

    +jfjdjfjsd           restricted

    @jgjjdj              restricted

but when i implement it on typescript file i got an error and giving the below result and error

ERROR SyntaxError: Invalid regular expression: /^[A-Za-z0-9$&,:;?#|' <>.^()%!(/)()(])([){}$~_]+[A-Za-z0-9$&+,:;=?@#|' <>.^*()%!(-)(/)(\)(])([){}*$~_]*$/: Unmatched ')'

    &jvjdjkfdkjkjd       not restricted
   
    sdsdas@-+++=         not restricted

    -jgjjdj              not restricted   --wrong(as - is in starting)

    =fjkdfjjd            not restricted   --wrong(as = is in starting)

    +jfjdjfjsd           not restricted   --wrong(as + is in starting)

     @jgjjdj              not restricted   --wrong(as @ is in starting)

0 Answers0