Home > other >  Regex validation which should have atleast one special character except special characters (? and _)
Regex validation which should have atleast one special character except special characters (? and _)

Time:10-27

I need a Regular expression validation which should have atleast any one special character except special characters (? and _).

Valid:

  1. abcd%&
  2. $ghksj

Invalid:

  1. hhsh?
  2. nxx_hus

I have tried this

^(?=[a-zA-Z0-9~@#$^*() =[\]{}|\\,.: -]*$)

CodePudding user response:

Use

^(?=[a-zA-Z0-9`!@#$%^&*() =\[\]{};':"\\|,.<>\/~-]*$).*

Regex proof

If lookaround not required:

^[a-zA-Z0-9`!@#$%^&*() =\[\]{};':"\\|,.<>\/~-]*$

Regex proof.

  • Related