ExtJS form validation includes null validation, simple validation with vtype format, advanced custom password authentication, use of regular expression validation, and so on://In Onready function () {} Ext.QuickTips.init (); Provides a hint information feature for a component, and the main message for the form is the error message for client validation. ext.form.field.prototype.msgtarget= ' side '; Hint, the enumeration value is: qtip-display prompts when the mouse moves over the control; title-is displayed in the browser's caption, but the test result is the same as Qtip; under-to display an error prompt underneath the control; side-displays an error icon to the right of the control and displays an error message when the mouse points to the icon. Default value; id-[element ID] Error prompt appears in HTML component of the specified ID 1. One of the simplest examples: null validation code as follows://null validation two parameters Allowblank:false//false can not be null, default is true blanktext:string//error message when null JS code for: code as follows: Var Form1 = new Ext.form.FormPanel ({ width:350, renderto: "Form1", title: "Formpanel", defaults:{ Xtype: "TextField", InputType: "Password"}, items:[ {fieldlabel: "Cannot be empty", allowblank:false,//no NULL allowed Blanktext: "Cannot be empty,"///error message, default is the This field is required! ID: "Blanktest", } ] }); 2. Use the VType format for simple verification. In this example of email validation, rewrite the above code's items configuration: code as follows: items:[ {fieldlabel: "Cannot be empty", vtype: "Email",//email format verification Vtypetext: "Not a valid email address",//error message, default value I won't say it. ID: "Blanktest", Anchor: "90%" } You can modify the VType for the following ExtJS vtype default support type for: validation//form 1.ALPHA//can only enter letters, can not enter other (such as numbers, special symbols, etc.) 2.alphanum//can only enter letters and numbers, can not enter other 3.email//email authentication, the required format is "" 4.url//url format verification, the required format is http://www.baidu.com 3. Advanced Custom Password validation The previous validation is ExtJS already provided, we can also customize the validation function. Code as follows:///First add the custom password validation function (or other name) with the Ext.apply method ext.apply (ext.form.vtypes,{ password: function (Val,field) {//val refers to the text box value here, field refers to the text box component, you want to understand this meaning if (field.confirmto) {//confirmto is our custom configuration parameter, Generally used to save the ID value of another component Var pwd=ext.get (FIELD.CONFIRMTO);//Get the value of that ID of Confirmto return (Val==pwd.getvalue ()); } return true; } }); //Configure the items parameter items:[{fieldlabel: "Password", ID: "Pass1", },{ fieldlabel: "Confirm password", ID: "Pass2", vtype: "Password",//Custom Authentication type Vtypetext: "Two times password inconsistent! ", confirmto:" Pass1,//The other component to compare id } 4. Use regular expression validation code as follows: New Ext.form.TextField ({ Fieldlabel: "Name", Name: "Author_nam", regex:/[u4e00-u9fa5]/,//regular expression between/...../.) [U4E00-U9FA5]: Only input Chinese . regextext: "Only Chinese!",//Regular expression error hint Allowblank:false//This validation is still valid. Don't be empty .
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.