Jump to content

Archived

This topic is now archived and is closed to further replies.

shan_cool

Validation

Recommended Posts

Hi all,

The defect id which i store in the MYSQL is 1,2,3 and so on....In my front end(PHP) it shld be displayed as 00001,00002,and so on,I made it displayed using Lpad in my select queries.
In one of my screen,when i enter the defect id,certain set of records shld be displayed and it wrks fine.
Now the pblm is when i enter the defect id as 1,the query is excuted which is obvious....
Now i need a validation to be carried out which checks for first 4 zeros of the number and then allows the user to get the query excuted.

Can anybody help me,
Thanks in advance,
Shan

Share this post


Link to post
Share on other sites
function checkForm(myForm)
{
if (myForm.myNumberField.length != 5)
{
alert ("Please enter 4 zeros before number");
myForm.myNumberField.focus();
return false;
}
return true;
}


<form on submit = "return checkForm(this)>

Share this post


Link to post
Share on other sites
regular expressions should be your best friend..

var emailRegex = new RegExp("^0{4}.{1}$");
var emailText = '00003';
if(emailRegex.test(emailText)){
document.write("number has 4 zeroes and a positive integer.");
}else{
document.write("not today, better make this function return true.");
}

this should match 4 zeroes than a non-zero integer, i'm sure this must have to be altered.

Share this post


Link to post
Share on other sites

×

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.