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.'; } 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.'; } 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.'; } ?> 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. Link to comment https://forums.phpfreaks.com/topic/85373-simple-regex-test-fails/#findComment-436351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.