I need Regex for english characters, hyphen and underscore
Example
Match :
govind-malviya govind_malviya govind123 govind
Not Match
govind malviya govind.malviya govind%malviya 腕錶生活 вкусно-же
In regular expressions, the hyphen ("-") notation has special meaning; it indicates a range that would match any number from 0 to 9. As a result, you must escape the "-" character with a forward slash ("\") when matching the literal hyphens in a social security number.
The _ (underscore) character in the regular expression means that the zone name must have an underscore immediately following the alphanumeric string matched by the preceding brackets. The . (period) matches any character (a wildcard).
Regex doesn't recognize underscore as special character.
$ means "Match the end of the string" (the position after the last character in the string).
try this out:
^[A-Za-z\d_-]+$
A-Za-z
would allow alphabets.\d
would allow numbers._
would allow underscore.-
would allow hyphen.
^
and $
represent the start and end of string respectively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With