Add condition to regex to match only ASCII characters -


i have regex:

/^(?=.*[a-z])(?=.*[a-z])(?=.*\d)\s{7,127}.+$/ (at least 1 uppercase, 1 downcase, 1 digit, no space, len 8 128)

i want add new condition: ascii chars

currently i'm trying with: /^(?=.*[a-z])(?=.*[a-z])(?=.*\d)(^\p{ascii})\s{7,128}.+$/

which works (doesn't match): "çko#1!rtsdsws"

but match (i want don't match because of ç): "kço#1!rtsdsws"

use positive lookahead check ascii character before matching each non-space character.

^(?=.*[a-z])(?=.*[a-z])(?=.*\d)(?:(?=\p{ascii})\s){8,128}$ 

or

^(?=.*[a-z])(?=.*[a-z])(?=.*\d)(?:(?=[[:ascii:]])\s){8,128}$ 

demo


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -