carley_bell Posted January 23, 2009 Share Posted January 23, 2009 Hi...again, I know this is probably really easy but... I am trying to validate my form and cannot figure out how to make sure field_1 is only alphanumeric. This is what I have attempted so far (please don't laugh) $alnum = !ereg("^[A-z0-9]*$"); // make sure both email addresses match if ($_POST['field_7'] != $_POST['field_8']) { die('The email addresses you entered do not match. Please use your browsers back button to go back to the form '); } // make sure userid is alphanumeric if ($_POST[$alnum . 'field_1']) { die('User ID should not contain any spaces or special characters. Please use your browsers back button to go back to the form '); } Quote Link to comment https://forums.phpfreaks.com/topic/142140-solved-easy-server-side-validation-question/ Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 if (!preg_match('/^[a-zA-Z0-9]+$/',$_POST[$alnum . 'field_1'])) { Quote Link to comment https://forums.phpfreaks.com/topic/142140-solved-easy-server-side-validation-question/#findComment-744535 Share on other sites More sharing options...
MadTechie Posted January 23, 2009 Share Posted January 23, 2009 Try this if (preg_match('/^[a-z0-9]*$/i', $_POST['field_1'])) { # It's alphanumeric } Quote Link to comment https://forums.phpfreaks.com/topic/142140-solved-easy-server-side-validation-question/#findComment-744536 Share on other sites More sharing options...
carley_bell Posted January 23, 2009 Author Share Posted January 23, 2009 Perfect!!! Thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/142140-solved-easy-server-side-validation-question/#findComment-744548 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.