ameyjah Posted April 1, 2009 Share Posted April 1, 2009 Hi friends, I need to see that user must enter single character (ranging from a to z (small letters only)). suppose user input is $input='a', then how do i use if condition. Link to comment https://forums.phpfreaks.com/topic/152119-solved-want-to-confirm-userinput-only-between-a-z/ Share on other sites More sharing options...
premiso Posted April 1, 2009 Share Posted April 1, 2009 <?php $input = $_GET['input']; if (strlen($input) == 1 && preg_match('~[a-z]~', $input)) { echo "Yep {$input} is a single letter and small."; }else { echo "Nope {$input} is not a single letter or small."; } ?> Link to comment https://forums.phpfreaks.com/topic/152119-solved-want-to-confirm-userinput-only-between-a-z/#findComment-798912 Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 I need to see that user must enter single character (ranging from a to z (small letters only)). Hehe, you mean lower-case... I you use regex like premiso exemplifies, it will be very easy to restrict what the user can enter. Link to comment https://forums.phpfreaks.com/topic/152119-solved-want-to-confirm-userinput-only-between-a-z/#findComment-798928 Share on other sites More sharing options...
RichardRotterdam Posted April 1, 2009 Share Posted April 1, 2009 or even simpler $input=$_POST['text']; if(ctype_lower ($input) && strlen($input)==1){ echo"lowercase char found "; }else{ echo "not valid input"; } Link to comment https://forums.phpfreaks.com/topic/152119-solved-want-to-confirm-userinput-only-between-a-z/#findComment-798963 Share on other sites More sharing options...
ameyjah Posted April 2, 2009 Author Share Posted April 2, 2009 thanks a lot. After giving some thought, i got the following idea. Solution: Check if the ASCII of the entered text is between 97 to 122. if(ord($record)>=97 || ord($record)<=122) echo "Yes"; else echo "No"; Link to comment https://forums.phpfreaks.com/topic/152119-solved-want-to-confirm-userinput-only-between-a-z/#findComment-799127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.