Tornado Class Library

Special Topic - Validation wih

Validation is for input fields primary in edit inputs. Pre-programmed masks and Perl based regular expressions can be used to validate th einput values. If user is using more IE browsers, a fancy color options can be used to reflect the real-time validity of the input text.

In order to use SuperValidator, you need to specify the  in the EditFlds parameters -.

Obj.dbEditGrid???Flds = (;,~)Field| Type | Tag | Def | ValueIndex | TextIndex | Notes | 
                    Mask | Event| Min | Max | Req | ErrorText| Oper| CompVal | Help| Title

Example -

Obj.dbEditUpdateFlds = "fi=0| ty=RONOUPdate,4, fi=HireDate| ty=TextCalendar, fi=HomePhone| ty=TEXT|
    mask=USPHONE| event=both| req=true| err=Must be XXX-XXX-XXXX, fi=ReportsTo| ty=SELECTBOX|
    val=EID| tex=FullName, fi=Notes| type=TextArea| tag=COLS=25 ROWS=5"

 

Pre-Programmed Masks

 

Standard Mask Regular Expression
EMAIL "\\A\\w\.+\\@(\\w*+\\.?)+\\Z"
PHONE \\A((\\+\\d+[- ])?\\(?\\d\\d\\d\\)?[- ])?\\d\\d\\d[- ]?\\d\\d\\d\\d\\Z
USPHONE \\A(\\(?\\d\\d\\d\\)?[- ])?\\d\\d\\d[- ]?\\d\\d\\d\\d\\Z
SSN \\A\\d\\d\\d-\\d\\d-\\d\\d\\d\\d\\Z
ISNUMBER \\A(-\\d)?\\d*\\.?\\d*( ?[eE]{1}[\\+\\-]?\\d+)?\\Z
ISPOSITIVE \\A\\d*\\.?\\d*\\Z
NOTBLANK \\A.*\\S.*\\Z
ISUPPER \\A[^a-z]*\\Z
ISLOWER \\A[^Aa-Z]*\\Z
CREDITCARD Internal

 

Edit Template Validation Macros

 
Standard Mask Regular Expression
[[UE::FieldIndex]]  Specify which field to process
[[UE::_TITLE]] TextHolder EditTitle
[[UE::_VALIDATOR_HEAD]] If Validator is used then youmust lay this tag
[[UE::_VALIDATOR_FOOT]] If Validator is used then youmust lay this tag
[[UE::_FORM]] Mandatory Tag
[[UE::_/FORM]] Mandatory Tag
[[UE::_NAV]] Navigation Bar

 

ServerSide Validation

When CompVal (Compare value) property is not blank, you are selecting the MagicCell type server side validation. The parameters in this field is in the format of Property~CompareValue(s). When the CompValue is a set, the delimiter will be the 3rd delimiter (def=~). When this is specified then the field or column (full screen) values will be send to the MagicCell validation filter. On top of the regular MagicCell filters, the RS (Regular expression) operator is added. upon any errors, a message will be displayed.

See MagicCell for details

 

User Javascript Validation With Validator

A new feature released in July 2007 - User Javascript Validation for the Validator.The feature insert a 'hook' into the Validator's submit 'Go' button to branch off to a user defined Javascript. This originally is a standard way to perform local validation and now combined with the very powerful Validator of ASP-db. The ASP-db Validator validates only the data in the TEXT type Form elements. Selectbox, Radios and other elements are not covered. The User Js Validation is implemented to cover these special elements. The following example addeed the UserValidateJs to the Validator to signal that wafter the Validator's validation, the user validation will be used.

The syntax is UserValidateJs=checkselect(thisform) ; thisform is an option to pass the form owner to the user Js.

'................... User Js Validation functyion ........................
Dim ta As String = "<script language='javascript'>" & vbCrLf
ta &= "function checkselect(thisform){" & vbCrLf
ta &= "if (thisform.ASPDB_UPDATE_16_0.options[thisform['ASPDB_UPDATE_16_0'].selectedIndex].value == '')" & vbCrLf
ta &= "{" & vbCrLf
ta &= "alert('ReportsTo Field cannot be Blank');" & vbCrLf
ta &= "return false;" & vbCrLf
ta &= "}" & vbCrLf
ta &= "else {return true;}" & vbCrLf
ta &= "}</script>" & vbCrLf

Dim Update As New Tornado.z
With Update
.dbUnit = 701
.dbMode = "ty=dual-horiz| sysind=t"
.dbSkin = 3
.dbDSN = "nwind.mdb"
.dbSQL = "Select * From employees"
.dbGridDisplayFlds = "0,1"
.dbValidatorParams = "code=/tornado/Jars|entry=false| UserValidateJs=checkselect(thisform)"
.dbEditUpdateFlds = "fi=0|ty=RONOUPdate,4,fi=HireDate|ty=TextCalendar, " & _
"fi=HomePhone|ty=TEXT|mask=USPHONE|event=both|req=true|err=Must be " & _
"XXX-XXX-XXXX,fi=ReportsTo|ty=SELECTBOX+B|val=EID|tex=FullName,fi=Notes|" & _
"type=TextArea|tag=COLS=25 ROWS=5"
.dbNavigationItem = "top,bottom,prev,next,update"
.dbBookMark = "employees;0"
.dbFormMagicCell = "fi=HireDate|macro=#Hiredate::d#"
.dbCommonTables = "index=EID,First,FullName|sql=Select employeeid,Firstname," & _
"Firstname & ' ' & Lastname from employees"
.dbLookUpFlds = "fi=EmployeeID|key=EID|look=FullName,fi=ReportsTo| key=EID|look=Fullname"
.dbTextHolder = "Title=Tornado Demo - Normal Update with Advanced Validation"
.dbSendHead = ta
.ASPdbNET()
End With

 

User Javascript Validation w/o Validator

 

An ID tag is added to Edit and GridEdit elements such that user can access the element via the following using Javascript ->

"if (document.getElementById('LastName').value == ''){" & _
"alert('LastName cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_2_0.value == ''){" & _
"alert('FirstName cannot be blank');return false;}" & _

In order to access vis the ID, you need a recent browser that supports the getElementById which is the same requirement for all the AJAX stuff.

So, for normal (w/o using validator) edit, we now have ID=LastName and for Grid Edit, we have LastName_row. Much easier to work with.

Note: For foreign language installation and the fieldname is in foreign language, you MUST use the NAME like ASPDB_ADD_1_0 and not the Fieldname. 
This browser problem was the result of a very long debug session with German and Russian users about 8 years ago and we discovered the debug.

See updated example below - The LastName and Notes fields are using the ID tag. Only 5 elements are covered in thsi example -

Dim ujs As String = "<script language='Javascript'>" & _
"function noblanks(thisform) {" & vbCrLf & _
"if (document.getElementById('LastName').value == ''){" & _
"alert('LastName cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_2_0.value == ''){" & _
"alert('FirstName cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_3_0.value == ''){" & _
"alert('Title cannot be blank');return false;}" & _
"else if (thisform.ASPDB_ADD_4_0.options[thisform['ASPDB_ADD_4_0'].selectedIndex].value == ''){" & _
"alert('Title of Courtesy cannot be blank');return false;}" & _
"if (document.getElementById('Notes').value == ''){" & _
"alert('Notes cannot be blank');return false;}" & _
"return true;}</script>"

Dim J As New Tornado.z
   With J
      .dbQP = "U=1| D=NWIND| Q=employees| S=8| gdf=0,1,2| Ni=b5, add| bm=employees;0| TH=title=No Blank in Add - User JS Validate"
      .dbEditValidateName = "noblanks(this)"
      .dbSendHead = ujs
      .dbCommonTables = "Index=TOC|Value=Mr.,Mrs.,Ms.,Dr. ; index=EID,FullName|sql=Select employeeid, Firstname & ' ' & Lastname from employees"
      .dbLookUpFlds = "fi=ReportsTo| key=EID|look=Fullname"
      .dbEditAddFlds = "1,2,3,fi=4|Ty=Selectbox+B|Text=TOC|Val=TOC,5,6,7, 8,9,10,11,12," & _
            "fi=ReportsTo|ty=SELECTBOX+B|val=EID|tex=FullName, fi=Notes|type=TextArea|tag=COLS=25 ROWS=5"
      .ASPdbNET()
End With

Send comments on this topic.
Copyright 1998-2006 ASP-db