<% formid=request("formid") response.ContentType="application/x-javascript" if not(isnumeric(formid)) then response.end '/// Get validation rules set conn=server.createobject("ADODB.Connection") conn.open connection psql="select fieldvalidation,stopby from xlaAFPforms where formid=" & formid set rs=conn.execute(psql) if not(rs.eof) then fieldvalidation=rs("fieldvalidation") stopby=rs("stopby") end if rs.close set rs=nothing conn.close set conn=nothing '/// Check if the form has expired if isdate(stopby) then if todaydate>stopby then if expiredmsg="" then expiredmsg="The form cannot be submitted\nThis form expired on " & stopby response.write "function xlaAFPvalidate(xlaAFPform){alert('" & preparemsg(expiredmsg) & "');return false;}" response.end end if end if '/// If no fields to validate then Do Nothing response.end if fieldvalidation="" then response.write "function xlaAFPvalidate(xlaAFPform){return true;}" response.end end if '/// get each line of code lines=split(fieldvalidation,vbcrlf) '/// Translate each line into the proper code for x=0 to ubound(lines) if instr(lines(x),":")>0 then statements=split(lines(x),":") fieldname=trim(statements(0)) rules=trim(statements(1)) '/// Process each rule : rule=split(rules," ") ruletext="" for y=0 to ubound(rule) '/// Is a comparison rule ? trule=lcase(rule(y)) if instr(trule,"=")<>0 then parts=split(trule,"=") if ubound(parts)=1 then tvalue=parts(1) '/// Rule Value tcompare=parts(0) '/// Comparison '/// If the value is numeric then the comparison can be made if isnumeric(tvalue) then if tcompare="maxlen" then ruletext=ruletext & "if (xlaAFPform." & fieldname & ".value.length>" & tvalue &"){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' cannot contain more than " & tvalue & " characters.',xlaAFPform." & fieldname &")}" if tcompare="minlen" then ruletext=ruletext & "if (xlaAFPform." & fieldname & ".value.length<" & tvalue &"){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' cannot contain less than " & tvalue & " characters.',xlaAFPform." & fieldname &")}" if tcompare="lt" or tcompare="lessthan" then ruletext=ruletext & "if (!isNumeric(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' is not numeric',xlaAFPform." & fieldname &")} else {if (xlaAFPform." & fieldname & ".value>=" & tvalue &"){return cancelsubmit('Field \'" & fieldname & "\' should be less than " & tvalue & "',xlaAFPform." & fieldname &")}}" if tcompare="gt" or tcompare="greaterthan" then ruletext=ruletext & "if (!isNumeric(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' is not numeric',xlaAFPform." & fieldname &")} else {if (xlaAFPform." & fieldname & ".value<=" & tvalue &"){return cancelsubmit('Field \'" & fieldname & "\' should be greater than " & tvalue & "',xlaAFPform." & fieldname & ")}}" end if end if else if trule="req" or trule="required" then ruletext=ruletext & "if (xlaAFPform." & fieldname & ".value==''){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' is required',xlaAFPform." & fieldname &")}" if trule="num" or trule="numeric" then ruletext=ruletext & "if (!isNumeric(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' is not numeric',xlaAFPform." & fieldname &")}" if trule="int" or trule="integer" then ruletext=ruletext & "if (!isInteger(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' is not integer',xlaAFPform." & fieldname &")}" if trule="nspc" or trule="nospaces" then ruletext=ruletext & "if (!noSpaces(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' cannot contain spaces.',xlaAFPform." & fieldname &")}" if trule="alnum" or trule="alphanumeric" then ruletext=ruletext & "if (!isAlphanumeric(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' can only contain alphanumeric characters.',xlaAFPform." & fieldname &")}" if trule="alpha" or trule="alphabetic" then ruletext=ruletext & "if (!isAlphabetic(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' can only contain alphabetic characters.',xlaAFPform." & fieldname &")}" if trule="email" then ruletext=ruletext & "if (!isEmail(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' does not contain a valid e-mail address.',xlaAFPform." & fieldname &")}" if trule="cc" or trule="creditcard" then ruletext=ruletext & "if (!isCC(xlaAFPform." & fieldname & ".value)){return cancelsubmit('Field \'" & replace(fieldname,"_"," ") & "\' is not a valid credit card number.',xlaAFPform." & fieldname &")}" end if next if fieldname<>"" and instr(fieldname," ")=0 then jsscript=jsscript & "if (xlaAFPform." & fieldname&"){" & ruletext &"}"&vbcrlf end if next %> // Absolute Form Processor XE V1.0 : Form Validation System // Copyright(c)2000 - 2003 XIGLA SOFTWARE // http://www.xigla.com function cancelsubmit(msg,element){ alert(msg); element.focus(); return false } function isNumeric(what){ if (what.search(/^[-+]?\d+(\.\d+)?$/) != -1) return true; else return false; } function isInteger(what){ if (what.search(/^[-+]?[1-9]\d*.?[0]*$/) != -1) return true; else return false; } function isEmail(what) { // Works if (what.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true; else return false; } function isAlphanumeric(what){ // ANY alphanumeric string with spaces, commas, dashes. if (what.search(/^[a-zA-Z0-9\s.\-]+$/) != -1) return true; else return false; } function isAlphabetic(what){ if (what.search(/^[a-zA-Z\s]+$/) != -1) return true; else return false; } function noSpaces(what){ if (what.search(/\s/) != -1) return false; else return true; } function isCC(what){ if (what.search(/^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$/) != -1) return true; else return false; } function xlaAFPvalidate(xlaAFPform){ <%=jsscript%> }