LanceT Posted April 21, 2007 Share Posted April 21, 2007 I want to check to see if there's only letters and numbers in a field, how would I go about doing this? Link to comment https://forums.phpfreaks.com/topic/47985-checking-user-input/ Share on other sites More sharing options...
corbin Posted April 21, 2007 Share Posted April 21, 2007 preg_match("([a-zA-Z0-9]", $variabletocheck) Look up regular expressions. Also, is_numeric could be used if you were making sure a field was just numeric. Link to comment https://forums.phpfreaks.com/topic/47985-checking-user-input/#findComment-234486 Share on other sites More sharing options...
mmarif4u Posted April 21, 2007 Share Posted April 21, 2007 if ( !preg_match('/^[a-zA-Z\" "]*$/', $name) ) { error('The Name that you have given is not valid.\\n'. 'Please try again.'); } if (preg_match('#^[0-9]{3}-[0-9]{7}$#', $hp)) {}else{ error('The Handphone Number that you have given is not Valid.\\n'. 'Please try again.'); } Link to comment https://forums.phpfreaks.com/topic/47985-checking-user-input/#findComment-234490 Share on other sites More sharing options...
LanceT Posted April 21, 2007 Author Share Posted April 21, 2007 also what if I wanted to check underscores (_) and dashes (-) ? Link to comment https://forums.phpfreaks.com/topic/47985-checking-user-input/#findComment-234492 Share on other sites More sharing options...
trq Posted April 21, 2007 Share Posted April 21, 2007 As has been said. Look up regular expressions. Link to comment https://forums.phpfreaks.com/topic/47985-checking-user-input/#findComment-234496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.