sstangle73 Posted August 17, 2007 Share Posted August 17, 2007 im drawing a blank how do you require at least one letter in a form? or fail if all #s? Quote Link to comment https://forums.phpfreaks.com/topic/65460-solved-require-letter/ Share on other sites More sharing options...
NArc0t1c Posted August 17, 2007 Share Posted August 17, 2007 Number check:\ <?php $Variable = $_POST['var']; if(!is_numeric($Variable)){ echo 'Not just numbers in there..'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65460-solved-require-letter/#findComment-326864 Share on other sites More sharing options...
sstangle73 Posted August 17, 2007 Author Share Posted August 17, 2007 $uname = $_POST['user']; if(is_numeric($uname)){ die('There has to be at least one letter in your username!'); } the script doesnt die it continues! Quote Link to comment https://forums.phpfreaks.com/topic/65460-solved-require-letter/#findComment-326884 Share on other sites More sharing options...
chocopi Posted August 17, 2007 Share Posted August 17, 2007 but surely if someone uses a symbol such as #,£,$,% then it will recognise that it is not a number so it will return true on !is_numeric ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/65460-solved-require-letter/#findComment-326890 Share on other sites More sharing options...
sstangle73 Posted August 18, 2007 Author Share Posted August 18, 2007 yeah but i need it to die on all #s [0-9] Quote Link to comment https://forums.phpfreaks.com/topic/65460-solved-require-letter/#findComment-327234 Share on other sites More sharing options...
sstangle73 Posted August 18, 2007 Author Share Posted August 18, 2007 /* Check if there are only numbers */ $uname = $_POST['user']; if(is_numeric($uname)){ die('There has to be at least one letter in your username!'); } worked now so im confuseddd! Quote Link to comment https://forums.phpfreaks.com/topic/65460-solved-require-letter/#findComment-327235 Share on other sites More sharing options...
NArc0t1c Posted August 18, 2007 Share Posted August 18, 2007 $uname = $_POST['user']; if(is_numeric($uname)){ die('There has to be at least one letter in your username!'); } the script doesnt die it continues! Sorry, i'm tend not to use the die function, I didn't type exit there. : ) Quote Link to comment https://forums.phpfreaks.com/topic/65460-solved-require-letter/#findComment-327358 Share on other sites More sharing options...
markjoe Posted August 18, 2007 Share Posted August 18, 2007 Define a regular expression pattern for the user name. "/[a-z]+[0-9]*/i" This would match anything with minimum 1 letter and 0 or more numbers. It is case-insensitive, but it can be changed to match anything you think of. if(preg_match("/[a-z]+[0-9]*/i",$input)){ //username is ok } Regular expressions can be difficult to get a hang of at first, but it is well worth the time and effort. In my opinion anyway. http://us3.php.net/manual/en/reference.pcre.pattern.syntax.php Quote Link to comment https://forums.phpfreaks.com/topic/65460-solved-require-letter/#findComment-327374 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.