PDA

View Full Version : Form Field


Soad
04-27-2010, 08:08 AM
I have a web form that needs a 12 digit serial number of a product to be entered can I have the field changed so that the user cant enter a number that is to short or to long but will only accept the 12 digits

Thanks

davidj
04-27-2010, 09:02 AM
you can do it in JS and PHP (for those that escape the JS check)

In JS it would be something like...



n = document.getElementById('idnumber');

if(n.length == 12){

// process form

}else{

// report error

}in PHP

$number = $_POST['idnumber'];

if(strlen($number)==12){

// process form

}else{

// report error

}You can set the char length of the form field to have a max length of 12

if you got jiggy with some AJAX (Jquery) you can force focus on that field until it contains 12 ints

Soad
04-27-2010, 09:28 AM
What is the easiest way to add this code ?

Thanks

DWcourse
04-27-2010, 01:00 PM
Dreamweaver (at least CS3 and CS4) offers Spry Form Validation fields that let you add this functionality.

davidj
04-27-2010, 03:48 PM
What is the easiest way to add this code

DWcourse nailed it