views:

12

answers:

1

Hi, I'm wondering if someone can help me. I have recently used this tutorial:

http://net.tutsplus.com/tutorials/php/create-a-signup-form-with-email-confirmation/

to develop a more complex sign up form for a competition for a client. Basically, the way the validation has been done is different to many other validation methods I've used before and don't understand how to implement it, for some additional requirements.

This is an example of the validation code that I have altered, to suit my form requirements:

//quick/simple validation
 if(empty($code)){ $action['result'] = 'error'; array_push($text,'You forgot to enter your entry code'); }
 if(empty($name)){ $action['result'] = 'error'; array_push($text,'You forgot to enter your name'); }
 if(empty($email)){ $action['result'] = 'error'; array_push($text,'You forgot to enter your email address'); } 

This code only validates that there is content in those fields. But, for example on the 'entry code' field, I would like to put a maximum character input there and restrict certain characters, as well as a standard 'email' validation, so that the form is sent through to the database correctly.

If anyone knows how I can do this, with this sign-up form in particular, please assist me, as every other method I've tried to work with this form hasn't worked and caused the form to error.

Thank you in advance.

A: 

I would have another if statement inside an event that checks the value of $code and run a compare against your specified length.

on change/keydown/blur $code.value.length should return you the number of characters in the field specified. If the value is not "correct" display your $text action message.

on $code keyup {

if(this.value.length > x || this.value.length < y) { alert a fail message! }

}

Calvin