Jump to content

optianal forum validation


ironsight2000

Recommended Posts

I need to make this so that if typed in it will validated it but if not pass it.

 

			if($_POST['Ext'] == 'Ext') {
	       $error_Ext = 'please enter Ext';
$errors ++;
	} else if(!eregi("^[0-9]{0,3}",$_POST['Ext'])) {
		$error_Ext = 'please enter a valid Ext';
$errors ++;
		}

}

Link to comment
https://forums.phpfreaks.com/topic/132503-optianal-forum-validation/
Share on other sites

You forgot the $ at the end of the regex.  Without it, something like 123fdss is valid.  $ signifies end of the string (the opposite of ^).  You also forgot the /'s to signify start and end of regex.

 

<?php
   $string = '1234';
   // $string can be any amount of only numbers
 if(!preg_match("/^[0-9]*$/",$string)) {
   echo "invalid<br/>";
   }
   // $string can be any number 1 to 3 digits
 if(!preg_match("/^[0-9]{1,3}$/",$string)) {
   echo "invalid<br/>";
   }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.