I need a reqular expression to not match this (/^[a-zA-Z][a-zA-Z0-9]+$/)
pattern, where the string needs to start with alphabet followed by number and alphabet, with no special characters.
I tried with (/^??[a-zA-Z]?![a-zA-Z0-9]+$/)
and not able to get appropriate answer.
Example:
P123454(Invalid)
PP1234(Invalid)
1245P(valid)
@#$124(valid)
Thanks in advance.
This regex might be helpful:
/^[^a-zA-Z]+.*$/g
Your every valid input (from the question) should be a match.
Explanation:
a-zA-Z
^
means start with, So it should start with an alphabetic letter, then any number \d
of alphabetic letters az
with i
case insensitive flag.
const check = (str) => { return /^[^az].*/i.test(str) } console.log(check('P123454')) console.log(check('PP1234')) console.log(check('1245P')) console.log(check('@#$124'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.