hoangthi Posted November 6, 2013 Share Posted November 6, 2013 I have a form that only accepts the string: Axxxxxxx (x is a number) EX: A1234567, A3145321 So, How can I check if the input is valid ? If user input: A1234567: True B1234567: False AA123121: False A11 31231: False Please help me! Link to comment https://forums.phpfreaks.com/topic/283662-check-if-a-string-is-true/ Share on other sites More sharing options...
.josh Posted November 6, 2013 Share Posted November 6, 2013 // 1 or more numbers following if ( preg_match('~^A[0-9]+$~',$string) ) { // true } // 2 or more numbers following if ( preg_match('~^A[0-9]{2,}$~',$string) ) { // true } // exactly 7 numbers following if ( preg_match('~^A[0-9]{7}$~',$string) ) { // true } // between 5 and 7 numbers following if ( preg_match('~^A[0-9]{5,7}$~',$string) ) { // true } Link to comment https://forums.phpfreaks.com/topic/283662-check-if-a-string-is-true/#findComment-1457232 Share on other sites More sharing options...
hoangthi Posted November 7, 2013 Author Share Posted November 7, 2013 Thanks you so much! Admin Link to comment https://forums.phpfreaks.com/topic/283662-check-if-a-string-is-true/#findComment-1457316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.