robcrozier Posted November 23, 2006 Share Posted November 23, 2006 ok, im trying to validate some form input using eregi, only i cant seem to allow the user to enter a return character without the eregi function discarding it and the error handler being raised. here's the code that im using to validate the string:[code]if (eregi ("^[[:alpha:]. ()_,'-]{1,}$", THE RETURNED STRING HERE){ // valid}else{ // error handler raised}[/code]Any suggestions as to why this will not allow a the return character?Cheers Quote Link to comment https://forums.phpfreaks.com/topic/28232-eregi-validation-help/ Share on other sites More sharing options...
NerdConcepts Posted March 2, 2007 Share Posted March 2, 2007 Sorry to bring this old post up, but well, no one answered; and it is something I would like to know. I am trying to validate a phone number. Well I want that to allow both ( and ) . Among other things....here is the code. I get an error that says: [color=red]eregi(): REG_BADBR[/color][code] if (eregi ('^[0-9.\(\)-]{10-15}$', stripslashes(trim($_POST['user_contact'])))) { $ucontact = escape_data($_POST['user_contact']); } else { $ucontact = FALSE; echo '<span class="error">Please enter a valid contact number.<br /></span>'; }[/code]I have tried quite a few things from ...0-9\.\(\)\- and other stuff like ...0-9.()-.. which i knew wouldn't work because eregi uses ( ) to section out things. So I've tried "escaping" the ( and ), like about, but nothing works... Quote Link to comment https://forums.phpfreaks.com/topic/28232-eregi-validation-help/#findComment-197531 Share on other sites More sharing options...
btherl Posted March 2, 2007 Share Posted March 2, 2007 That's not the problem.. () is perfectly fine within []. The problem is that {10-15} should be {10,15}. I agree that the error message is NOT helpful Quote Link to comment https://forums.phpfreaks.com/topic/28232-eregi-validation-help/#findComment-197543 Share on other sites More sharing options...
NerdConcepts Posted March 2, 2007 Share Posted March 2, 2007 Thanks, I hate it when I make a stupid mistake. Just in case someone wants to know the final eregi() code...here it is[code]if (eregi ('^[0-9.\(\)-]{10,15}$', stripslashes(trim($_POST['user_contact'])))) {[/code]I am going to modify the code soon to make it where it requires '(' 3 digits ')' 3 digits '.' 4 digits (111)111.1111 so it will fully validate a phone number. Not full sure how to do it, but shouldn't be hard. Quote Link to comment https://forums.phpfreaks.com/topic/28232-eregi-validation-help/#findComment-197549 Share on other sites More sharing options...
btherl Posted March 2, 2007 Share Posted March 2, 2007 If you require area code it's simple.. and here you need to escape the brackets.[code=php:0]'\(?[0-9]{3}\)?[0-9]{3}[.-]?[0-9]{4}'[/code]You might want to strip spaces first in case someone adds them in. I made some things optional with "?", and allowed either "." or "-". This regexp might be too strict, since people might use other characters as seperators. Quote Link to comment https://forums.phpfreaks.com/topic/28232-eregi-validation-help/#findComment-197563 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.