Jump to content


Disabling / input or space bar input

  • Please log in to reply
3 replies to this topic

#1 dc_jt

  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 17 October 2006 - 02:41 PM

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:

<div class="formwrapper">
				  <div class="textlabel">Name</div><div class="formlabel"> <input name="Name" type="text" class="dataform" value="<?=(stripslashes($_POST['Name']))?>" />
				<div class="textlabel">Email</div>
				<div class="formlabel"> <input name="Email" type="text" class="dataform" value="<?=(stripslashes($_POST['Email']))?>"/>
				<div class="textlabel">Address</div>
				<div class="formlabel"> 
				  <textarea name="Address" rows="2" wrap="virtual" class="dataform"><?=(stripslashes($_POST['Address']))?></textarea>
				<div class="textlabel">Business Name </div>
				<div class="formlabel"> <input name="Business_Name" type="text" class="dataform" value="<?=(stripslashes($_POST['Business_Name']))?>"/>
				<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 class="textlabel">Comments</div>
				<div class="formlabel"> 
				  <textarea name="Comments" rows="2" wrap="virtual" class="dataform"><?=(stripslashes($_POST['Comments']))?></textarea>
				<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"/>

#2 michaellunsford

  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 17 October 2006 - 03:58 PM

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 AndyB's CAPTCHA Script
        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/>";

PS> There's a regular expression forum here at PHPfreaks. http://www.phpfreaks...board,43.0.html

#3 dc_jt

  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 17 October 2006 - 04:05 PM

Ive done the email validation thats in my class.

I just wanted to stop people from just simply pressing the space bar rather than input data

Thanks anyway for your help

#4 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 October 2006 - 05:11 PM

Use regualar expressions again then.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users