Mateobus Posted July 31, 2006 Share Posted July 31, 2006 I am trying to write a php function that validates a username and password. To keep things simple i want to allow only letters and numbers upper and lower case allowed. Is there a good function for this? Link to comment https://forums.phpfreaks.com/topic/16153-php-form-validation/ Share on other sites More sharing options...
Caesar Posted July 31, 2006 Share Posted July 31, 2006 If you want to define what characters to allow/disallow, look into regular expressions. Link to comment https://forums.phpfreaks.com/topic/16153-php-form-validation/#findComment-66707 Share on other sites More sharing options...
gijew Posted July 31, 2006 Share Posted July 31, 2006 This isn't perfect but...if (preg_match('/^[0-9a-zA-Z]+$/i', $_POST['FieldName'])) { echo 'matches';} else { echo 'no match';} Link to comment https://forums.phpfreaks.com/topic/16153-php-form-validation/#findComment-66710 Share on other sites More sharing options...
wildteen88 Posted August 1, 2006 Share Posted August 1, 2006 [quote author=gijew link=topic=102502.msg406858#msg406858 date=1154386656]This isn't perfect but...if (preg_match('/^[0-9a-zA-Z]+$/i', $_POST['FieldName'])) { echo 'matches';} else { echo 'no match';}[/quote]if you have the i modifier, you dont need the a-z bit in the expression gijew. So the expression can be just:[code]/^[0-9A-Z]+$/i[/code] Link to comment https://forums.phpfreaks.com/topic/16153-php-form-validation/#findComment-66904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.