> Hello all,
> I need a script that will validate a text field which contains units of an
> apt complex. Valid value would be 1,2,3,4 or 1-4 or 1a,2b,3c,4b (coma
> delimited list with range). All other formats would be invalid. The
> following is what I have so far but doesn't seem to work all that well.
> It doesn't catch invalid formats if the user puts in characters after a
> number
>
> (1=, 1&, 1*, -1..etc..) Any help would be appreciated, thanks in advance.
Hi Tim... You're probably doing yourself a slight disservice by trying to
parse the commas yourself individually... I would instead use
string.split(",") which is the javascript equivalent of listtoarray() to
create an array from your string and then loop over the array...
function testApts() {
var x = 0;
var y = 0;
var temp = "";
var myrange = new Array("");
var validchars = " -0123456789abcdefghijklmnopqrstuvwxyz";
var apts = document.newCaseInfo.unitInDetail.value.split(",");
for (x = 0 ; x < apts.length ; x++) {
temp = "";
for (y = 0 ; y < apts[x].length ; y++) {
if (validchars.indexOf(apts[x].charAt(y))<0)
{ temp += apts[x].charAt(y); }
}
myrange = temp.split("-");
for (y = 0 ; y < myrange.length ; y++) {
if ("0123456789".indexOf(myrange[y].charAt(0))<0) { return
false; }
}
}
return true;
}
This function will strip any unexpected characters ( including spaces ) and
return false if the first character or the first character following the -
is a letter...
hth
S. Isaac Dealey
Certified Advanced ColdFusion 5 Developer
www.turnkey.to
954-776-0046
______________________________________________________________________
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists