Jump to content

Disabling / input or space bar input


dc_jt

Recommended Posts

Hi I have created a form where a user inputs their details.

I want to be able to make the form not accept if someone simply just enters a load of ///// or just presses space bar to fill in the form.

I thought stripslashes would do this but it doesnt. Any ideas?

Here is my form:

[code]
<div class="formwrapper">
  <div class="textlabel">Name</div><div class="formlabel"> <input name="Name" type="text" class="dataform" value="<?=(stripslashes($_POST['Name']))?>" />
</div>
<div class="textlabel">Email</div>
<div class="formlabel"> <input name="Email" type="text" class="dataform" value="<?=(stripslashes($_POST['Email']))?>"/>
</div>
<div class="textlabel">Address</div>
<div class="formlabel">
  <textarea name="Address" rows="2" wrap="virtual" class="dataform"><?=(stripslashes($_POST['Address']))?></textarea>
</div>
<div class="textlabel">Business Name </div>
<div class="formlabel"> <input name="Business_Name" type="text" class="dataform" value="<?=(stripslashes($_POST['Business_Name']))?>"/>
</div>
<div class="textlabel">Type of Business </div>
<div class="formlabel"> <input name="Type_of_Business" type="text" class="dataform" value="<?=(stripslashes($_POST['Type_of_Business']))?>"/>
</div>
<div class="textlabel">Comments</div>
<div class="formlabel">
  <textarea name="Comments" rows="2" wrap="virtual" class="dataform"><?=(stripslashes($_POST['Comments']))?></textarea>
</div>
<div class="textlabel">&nbsp;</div><div class="formlabel">
  <input name="Submit" type="submit" class="databut" value="Submit" />
    <input type="hidden" name="mode" value="apply" />
    <br class="clear"/>
</form>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/24212-disabling-input-or-space-bar-input/
Share on other sites

You can handle spaces with trim(), but regular expression is much more powerful. If you know regex, you can probably figure out how to validate any part of your form. Here's an email validation example:

Borrowed from [url=http://www.digitalmidget.com/php_noob/captcha.php]AndyB's CAPTCHA Script[/url]
[code]
        if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
            $err.= $email. " is not a valid email address.<br/>";
        }
[/code]

[b]PS>[/b] There's a regular expression forum here at PHPfreaks. [url=http://www.phpfreaks.com/forums/index.php/board,43.0.html]http://www.phpfreaks.com/forums/index.php/board,43.0.html[/url]

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.