ironsight2000 Posted November 13, 2008 Share Posted November 13, 2008 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 More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 What? Link to comment https://forums.phpfreaks.com/topic/132503-optianal-forum-validation/#findComment-689009 Share on other sites More sharing options...
ironsight2000 Posted November 13, 2008 Author Share Posted November 13, 2008 I have a forum that has phone number i need to add a extension to the forum. I need it so that the user can only put numbers in and not letters or symbols. Link to comment https://forums.phpfreaks.com/topic/132503-optianal-forum-validation/#findComment-689012 Share on other sites More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 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/>"; } ?> Link to comment https://forums.phpfreaks.com/topic/132503-optianal-forum-validation/#findComment-689045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.