If I had a webpage and I neeed to ensure user input for a variable is only letters (upper and lower), numbers and dashes and the length had to be exactly 20 chars in length, how would one perform that?
This is pretty easy to do using regular expressions:
echo preg_match('/^[0-9a-zA-Z\-]{20}$/', 'abcd');
0
echo preg_match('/^[0-9a-zA-Z\-]{20}$/', 'abcdefghijkmlnopqrst');
1
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