Guest kilbad Posted August 4, 2006 Share Posted August 4, 2006 I have this form to enter a text message and e-mail address that then sends the text to me. I want to add validation to the form, and I think I am close but having problems with the preg_match statement (I think that's the problem..but maybe not). Would someone be willing to look at my code and see what I am doing wrong?Thanks so much!Brendan[code]<?php@extract($_POST);$email = stripslashes($email);$text = stripslashes($text);function check_field1($field_name_1){if(!preg_match('/^[A-z0-9\._-]+[@][A-z0-9_-]+([.][A-z0-9\._-]+)+[A-z]{2,4}$/',$field_name_1)) return TRUE;else return FALSE;}function check_field2($field_name_2){if(!preg_match("/[^0-9\ ]+$/",$field_name_2)) return TRUE;else return FALSE;}$error=0;if(!check_field1($email)){$error++;}if(!check_field2($text)){$error++;}if($error == "0"){mail('myemail@example.com',$email,$text," ");header("message_sent.php");}else{header("error.php");}?>[/code] Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 4, 2006 Share Posted August 4, 2006 you can't have A-z.. split them into a-zA-Z Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 4, 2006 Share Posted August 4, 2006 Which check_field. produces an error? Quote Link to comment Share on other sites More sharing options...
Guest kilbad Posted August 4, 2006 Share Posted August 4, 2006 I changed the code to this, but the form still results in the error page being loading. I still think it's a problem with my preg_match statements. Bascally, I am trying to code preg_match statements that only allow characters: A-Z, 0-9, ä, ö, ü, periods, hyphens, spaces, AND (with regard to the e-mail field) the @ symbol... any suggestions? thx again[code]<?php@extract($_POST);$email = stripslashes($email);$text = stripslashes($text);function check_field1($field_name_1){if(!preg_match('/^[a-zA-Z0-9\._-]+[@][A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1)) return TRUE;else return FALSE;}function check_field2($field_name_2){if(!preg_match("/[^a-zA-Z0-9\]+$/",$field_name_2)) return TRUE;else return FALSE;}$error=0;if(!check_field1($email)){$error++;}if(!check_field2($text)){$error++;}if($error == "0"){mail('myemail@example.com',$email,$text," ");header("message_sent.php");}else{header("error.php");}?>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 4, 2006 Share Posted August 4, 2006 try this okif(!preg_match('/^[a-zA-Z0-9\._-]+@[A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1)) Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 4, 2006 Share Posted August 4, 2006 [code]<?phpif(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$$field_name_1)) {echo " sorry do not use your email address in the text box!";}[/code]tell me if that what you wanted ok. Quote Link to comment Share on other sites More sharing options...
Guest kilbad Posted August 4, 2006 Share Posted August 4, 2006 Sorry this is taking me so long to figure out... redarrow, I tried your preg_match, and it did not work... here is my code now.. also, I did not follow your last post (with the eregi statement). I want to be able to have an e-mail validate in field 1. Field 2 is for the text message. Again, I am trying to code preg_match statements that only allow characters: A-Z, 0-9, ä, ö, ü, periods, hyphens, spaces, AND (with regard to the e-mail field (field 1)) the @ symbol. Again, sorry I am php-retarded today! thx for the help[code]<?php@extract($_POST);$email = stripslashes($email);$text = stripslashes($text);function check_field1($field_name_1){if(!preg_match('/^[a-zA-Z0-9\._-]+@[A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1)) return TRUE;else return FALSE;}function check_field2($field_name_2){if(!preg_match("/[^0-9\ ]+$/",$field_name_2)) return TRUE;else return FALSE;}$error=0;if(!check_field1($email)){$error++;}if(!check_field2($text)){$error++;}if($error == "0"){mail('textmessage.secured@kilbad.com',$email,$text," ");header("location:index.php?id=message_sent");}else{header("location:index.php?id=badform");}?>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 4, 2006 Share Posted August 4, 2006 i dont see what your trying to do can you kindly show the format that you dont wont shown Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 4, 2006 Share Posted August 4, 2006 my eregi code is just like preg_match and works as good ok try it your see. Quote Link to comment Share on other sites More sharing options...
Guest kilbad Posted August 4, 2006 Share Posted August 4, 2006 I'm not sure what you are asking? If you want the address to the pages I am using, here they are:The text message form:: http://kilbad.com/index.php?id=test_textmessageThe error page:: http://kilbad.com/index.php?id=badformThe message sent page:: http://kilbad.com/index.php?id=message_sentAnd again, here is the code to my text message script, called "secured_process_textmessage.php"::[code]<?php@extract($_POST);$email = stripslashes($email);$text = stripslashes($text);function check_field1($field_name_1){if(!preg_match('/^[a-zA-Z0-9\._-]+@[A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1)) return TRUE;else return FALSE;}function check_field2($field_name_2){if(!preg_match("/[^0-9\ ]+$/",$field_name_2)) return TRUE;else return FALSE;}$error=0;if(!check_field1($email)){$error++;}if(!check_field2($text)){$error++;}if($error == "0"){mail('textmessage.secured@kilbad.com',$email,$text," ");header("location:index.php?id=message_sent");}else{header("location:index.php?id=badform");}?>[/code] Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 4, 2006 Share Posted August 4, 2006 you still have A-z in your second and third character class.[code]<?phppreg_match('/^[a-zA-Z0-9\._\-]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9\_\-]+)+[a-zA-Z]{2,4}$/',$field_name_1)[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 4, 2006 Share Posted August 4, 2006 [code]<?php@extract($_POST);$email = stripslashes($email);$text = stripslashes($text);function check_field1($field_name_1){// eregi checks the email address format.if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$field_name_1)) return TRUE;else return FALSE;}function check_field2($field_name_2){if(!preg_match("/[^0-9\ ]+$/",$field_name_2)) return TRUE;else return FALSE;}$error=0;if(!check_field1($email)){$error++;}if(!check_field2($text)){$error++;}if($error == "0"){mail('textmessage.secured@kilbad.com',$email,$text," ");header("location:index.php?id=message_sent");}else{header("location:index.php?id=badform");}?>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 4, 2006 Share Posted August 4, 2006 there you go WOW preg_match[code]<?phpif(preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $field_name_1)) return true;?>[/code] Quote Link to comment Share on other sites More sharing options...
Guest kilbad Posted August 5, 2006 Share Posted August 5, 2006 ok, I tried the script you posted two ago, and after reading up on eregi, that now makes sense to me. However, I still get the error page when I try to send a text. Do I need to be including uppercase A-Z in the eregi too? Also, is second preg_match wrong if I am trying to validate a message of text?thanks again Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 5, 2006 Share Posted August 5, 2006 have you tried mine? Quote Link to comment Share on other sites More sharing options...
Guest kilbad Posted August 5, 2006 Share Posted August 5, 2006 I did, and got a "Parse error: syntax error, unexpected T_RETURN" after adding in the[code]if(preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $field_name_1)[/code] Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 5, 2006 Share Posted August 5, 2006 missing a closing ):[code]if(!preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $field_name_1)){ ....}[/code] Quote Link to comment Share on other sites More sharing options...
Guest kilbad Posted August 5, 2006 Share Posted August 5, 2006 I finally got it working! thank you all for your help Quote Link to comment 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.