Jump to content

Recommended Posts

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?");

}

Link to comment
https://forums.phpfreaks.com/topic/70847-solved-removing-special-characters/
Share on other sites

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,

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.