monkeybidz Posted September 27, 2007 Share Posted September 27, 2007 I have a form that has a text box: <input name="weight" type="text" id="weight" size="10" maxlength="5"> When to form is submitted, how do i make it to where the users cannot add any special characters like a comma for instance. This field is for a weight result value, but i need it to be all numeric at result. How can i strip it or make it return an erro on submit. Currently my error system is like so: if($weight == ) { //This is where i want to add the check for special characters// $msg[] = $error7; header("Location: quote_error.php?"); } Quote Link to comment https://forums.phpfreaks.com/topic/70847-solved-removing-special-characters/ Share on other sites More sharing options...
hemlata Posted September 27, 2007 Share Posted September 27, 2007 Hello, You can do this by using preg_match. See the given example for reference. Lets us consider the form is posted with a filled textbox having name as 'txtName' $result = preg_match("/^(\d+)+$/", $_POST['txtName']); // Executes if match found if ($result !=0) { echo "<center><font color='#FF0000'>Entered number is valid number :: </font>".$_POST['txtName']."</center><br>"; } // else execute else { echo "<center><font color='#FF0000'>Entered text is invalid :: </font>".$_POST['txtName']."</center><br>"; } Hope this might solve your issue. Regards, Quote Link to comment https://forums.phpfreaks.com/topic/70847-solved-removing-special-characters/#findComment-356304 Share on other sites More sharing options...
monkeybidz Posted October 4, 2007 Author Share Posted October 4, 2007 You lead me in the right direction. I used this instead. if(!preg_match("/^(\d+)+$/", $weight)){ $msg[] = $error10; } Thanks a bunch! Quote Link to comment https://forums.phpfreaks.com/topic/70847-solved-removing-special-characters/#findComment-361384 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.