A compact version for the world of UTF-8, which will correspond to international letters and numbers.
/^[\p{L}\p{N}*-]+$/u
Explanation:
- [] => character class definition
- p {L} => matches any letter character from any language
- p {N} => matches any kind of numeric character
- * - => matches asterisk and hyphen
- + => Quantifier - Matches between one to unlimited time (greedy)
- / u => Unicode modifier. Template strings are treated as UTF-16. Also calls escape sequences to match Unicode characters.
Note that if the hyphen is the last character in the class definition, it does not need to be escaped . If a dash appears elsewhere in the class definition, it needs to be escaped , since it will be treated as a range symbol, not a hyphen.
source share