Lassie Posted January 10, 2008 Share Posted January 10, 2008 I need to check that input is alpha numeric and use the following code which fails. Is there a mistake in the eregi code? if (eregi ('^[[:alnum:]]$', stripslashes(trim($_POST['address'])))) { $add = escape_data($_POST['address']); } else { $errors[] = 'You forgot to enter your address.'; } Quote Link to comment https://forums.phpfreaks.com/topic/85373-simple-regex-test-fails/ Share on other sites More sharing options...
Lassie Posted January 10, 2008 Author Share Posted January 10, 2008 I realise that I also need to allow spaces in the address line so I have modified the expression but it still fails. can anyone help please. // Check for a address. if (eregi ('^[[:alnum:]][[:space:]]{30}$', stripslashes(trim($_POST['address'])))) { $add = escape_data($_POST['address']); } else { $errors[] = 'You forgot to enter your address.'; } Quote Link to comment https://forums.phpfreaks.com/topic/85373-simple-regex-test-fails/#findComment-435696 Share on other sites More sharing options...
dsaba Posted January 10, 2008 Share Posted January 10, 2008 <?php if (eregi ('[a-z0-9 ]+', stripslashes(trim($_POST['address'])))) { $add = escape_data($_POST['address']); } else { $errors[] = 'You forgot to enter your address.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85373-simple-regex-test-fails/#findComment-435889 Share on other sites More sharing options...
Lassie Posted January 11, 2008 Author Share Posted January 11, 2008 Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/85373-simple-regex-test-fails/#findComment-436351 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.