blessedame
07-16-2003, 07:05 AM
Hi Guys,
I need your help with this one...
This is the scenario,
the serial number entered in this form could be:
12 characters long - but 5th digit must be 4 or 6
and nowhere can the character be anything but 0123456789abcdefghABCDEFGH
15 characters long - first 3 digits must be '151' and the rest anything between 0123456789abcdefghABCDEFGH
This has already been done in the code below.
(was done way before my time so I couldnt even decipher that) :-)
Now we have a new scenario (including what we currently have):
Serial number could be 12 characters long - first digit must be a 6 and 2nd character must be D,E or F.
This new scenario is what I need to include in the code.
This is the script I currently have:
<SCRIPT LANGUAGE="JavaScript">
function validateAll(form) {
serialnumber = trim(form.serialnumber.value) ;
if(serialnumber == ""){
alert("Please enter your serial number");
return false ;
}else if( ! validatefig(serialnumber) ){
return false ;
}else if( ! validatefigNew(serialnumber) ){
return false ;
}
return true ;
}
function trim(strText) {
// this will get rid of leading spaces
while (strText.substring(0,1) == ' ')
strText = strText.substring(1, strText.length);
// this will get rid of trailing spaces
while (strText.substring(strText.length-1,strText.length) == ' ')
strText = strText.substring(0, strText.length-1);
return strText;
}
// validating serial numbers
function validatefig(serialnumber) {
if (isIndexOf(serialnumber, "-+/? !@#$%^&*()_~`:;") ) {
alert("Invalid Serial Number, please try again");
return false;
}
var numeric = "0123456789abcdefghABCDEFGH" ;
for (i=0; i<serialnumber.length; i++) {
if (numeric.indexOf(serialnumber.charAt(i))==-1){
alert("Invalid serial number, please try again");
return false;
}
}
return true;
}
function validatefigNew(serialnumber) {
if (serialnumber.length == 12) {
if (serialnumber.charAt(4) == '4') {
return true;
} else if (serialnumber.charAt(4) == '6') {
return true;
} else {
alert("Invalid Serial Number, please try again");
return false;
}
}else if (serialnumber.length == 15){
if (serialnumber.substr(0,3) == '151'){
return true;
}else {
alert("Invalid Serial Number, please try again.");
return false;
}
}else {
alert("Invalid Serial Number, please try again.");
return false;
}
}
function isIndexOf(field, characters) {
for (var i = 0; i < characters.length; i++) {
if (field.indexOf(characters.charAt(i)) != -1) {
return true;
}
}
return false;
}
I hope this all make sense.
Thanks everyone.
I need your help with this one...
This is the scenario,
the serial number entered in this form could be:
12 characters long - but 5th digit must be 4 or 6
and nowhere can the character be anything but 0123456789abcdefghABCDEFGH
15 characters long - first 3 digits must be '151' and the rest anything between 0123456789abcdefghABCDEFGH
This has already been done in the code below.
(was done way before my time so I couldnt even decipher that) :-)
Now we have a new scenario (including what we currently have):
Serial number could be 12 characters long - first digit must be a 6 and 2nd character must be D,E or F.
This new scenario is what I need to include in the code.
This is the script I currently have:
<SCRIPT LANGUAGE="JavaScript">
function validateAll(form) {
serialnumber = trim(form.serialnumber.value) ;
if(serialnumber == ""){
alert("Please enter your serial number");
return false ;
}else if( ! validatefig(serialnumber) ){
return false ;
}else if( ! validatefigNew(serialnumber) ){
return false ;
}
return true ;
}
function trim(strText) {
// this will get rid of leading spaces
while (strText.substring(0,1) == ' ')
strText = strText.substring(1, strText.length);
// this will get rid of trailing spaces
while (strText.substring(strText.length-1,strText.length) == ' ')
strText = strText.substring(0, strText.length-1);
return strText;
}
// validating serial numbers
function validatefig(serialnumber) {
if (isIndexOf(serialnumber, "-+/? !@#$%^&*()_~`:;") ) {
alert("Invalid Serial Number, please try again");
return false;
}
var numeric = "0123456789abcdefghABCDEFGH" ;
for (i=0; i<serialnumber.length; i++) {
if (numeric.indexOf(serialnumber.charAt(i))==-1){
alert("Invalid serial number, please try again");
return false;
}
}
return true;
}
function validatefigNew(serialnumber) {
if (serialnumber.length == 12) {
if (serialnumber.charAt(4) == '4') {
return true;
} else if (serialnumber.charAt(4) == '6') {
return true;
} else {
alert("Invalid Serial Number, please try again");
return false;
}
}else if (serialnumber.length == 15){
if (serialnumber.substr(0,3) == '151'){
return true;
}else {
alert("Invalid Serial Number, please try again.");
return false;
}
}else {
alert("Invalid Serial Number, please try again.");
return false;
}
}
function isIndexOf(field, characters) {
for (var i = 0; i < characters.length; i++) {
if (field.indexOf(characters.charAt(i)) != -1) {
return true;
}
}
return false;
}
I hope this all make sense.
Thanks everyone.