Tim,

Check out qForms:
http://www.pengoworks.com/qforms/

While it doesn't have the exact type of validation you're looking for,
it'll be very easy to write on. Once written, it'll be completely
re-usable from page to page. 

There are detailed examples of the API at:
http://www.pengoworks.com/qForms/docs/examples/index.htm

Best of all it's free and it works!

-Dan

> -----Original Message-----
> From: Tim Do [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 18, 2002 12:34 PM
> To: CF-Talk
> Subject: OT: js validation
> 
> 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.
> 
>       var pos = 0;
>       var nextpos = 0;
>       var str = document.newCaseInfo.unitInDetail.value;
> 
>       nextpos = str.indexOf(",",pos);
> 
>       for(var i=0; nextpos !=-1; i++)
>       {
>               if(!isAlphaNumeric(str.substring(pos,nextpos)))
>               {
>                       if(!isNumSpan(str.substring(pos,nextpos)))
>                       {
>                               notifyClientOnError();
>                               return false;
>                       }
>               }
>               pos = nextpos+1;
>               nextpos = str.indexOf(",",pos);
>       }
>       if(!isAlphaNumeric(str.substring(pos,str.length)))
>       {
>               if(!isNumSpan(str.substring(pos,str.length)))
>               {
>                       notifyClientOnError();
>                       return false;
>               }
>       }
> 
>       return true;
> }
> 
> function notifyClientOnError()
> {
>       alert('Please check the Units Details Format...try again');
> }
> 
> function isInteger(s)
> {
>         for (i = 0; i < s.length; i++)
>         {
>               var c = s.charAt(i);
>               if (!isDigit(c))
>               {
>                       return false;
>               }
>         }
>       return true;
> }
> 
> function isDigit(myChar)
> {
>       return (myChar >= "0") && (myChar <= "9");
> }
> 
> function isNumSpan(numStr)
> {
>       var npos = 0;
>       var nextnpos = 0;
> 
>       nextnpos = numStr.indexOf("-",npos);
> 
>       if(!isInteger(numStr.substring(npos,nextnpos)))
>               return false;
> 
>       if(!isInteger(numStr.substring(nextnpos+1,numStr.length)))
>               return false
> 
>       return true
> }
> 
> function isAlphaNumeric(string)
> {
>       var hasDash = string.indexOf("-");
> 
>       if(hasDash==-1)
>       {
>               re = /[0-9]+[A-Za-z]*/
>               return  re.exec(string);
>       }
>       else
>               return false;
> }
> 
> 
______________________________________________________________________
Get the mailserver that powers this list at http://www.coolfusion.com
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

Reply via email to