富阳网站建设公司,wordpress 个人网站,优质高职院校建设网站,成都app开发外包Validator是Atlas提供的一组验证用户输入的客户端组件#xff0c;用来检查InputControl类型的Atlas控件#xff0c;例如Web.UI.TextBox的输入数据。在ASP.NET中提供了一组服务器端的验证控件#xff0c;Atlas中的Validator在客户端也提供了同样的功能。 主要内容 1#xff…Validator是Atlas提供的一组验证用户输入的客户端组件用来检查InputControl类型的Atlas控件例如Web.UI.TextBox的输入数据。在ASP.NET中提供了一组服务器端的验证控件Atlas中的Validator在客户端也提供了同样的功能。 主要内容 1Validators概述 2完整示例 一Validators概述 Validator是Atlas提供的一组验证用户输入的客户端组件用来检查InputControl类型的Atlas控件例如Web.UI.TextBox的输入数据。在ASP.NET中提供了一组服务器端的验证控件Atlas中的Validator在客户端也提供了同样的功能。Atlas提供的Validator如下所示 1requiredFieldValidator检查是否有数据输入。 2typeValidator检查输入的数据是否为特定的类型。 3rangeValidator检查输入的值是否在一个范围之内。 4customValidator用自定义的验证函数验证输入。 5regexValidator用指定的正则表达式验证输入。 某个Atlas客户端控件的Validator可被定义成一个集合当控件的propertyChanged事件被引发时Atlas将调用Validator集合中的所有Validator去验证输入的数据。在验证的过程中一旦失败这个Validator的validationMessage将被设置。Validator可以以组的形式验证一组控件的输入并统一显示错误信息。您还可以指定一个validationErrorLabel控件关联于某个将被验证的输入控件它可以显示验证过程中的错误并可以自定义错误提示。[来自于Dflying的介绍] 二完整示例 下面针对这几种Validator做几个简单的小例子。 1requiredFieldValidator 检测是否有有数据输入用一个textbox接收用户输入用一个label来显示错误信息
div h3Example 1: Required Field Validator/h3 br / input typetext idvalue1TextBox classinput / nbsp; span idvalidator1 stylecolor: redYou must enter some text/span br / br / Text: span idvalue1Label classresult/span br / /div 编写Atlas脚本分别用一个requiredFieldValidator和validtionErrorLabel并且把用户输入的数据显示在一个label上在validationErrorLabel中用associatedControl来关联要验证的控件
script typetext/xml-script page xmlns:scripthttp://schemas.microsoft.com/xml-script/2005 components textBox idvalue1TextBox validators requiredFieldValidator errorMessageYou must enter some text./ /validators /textBox validationErrorLabel idvalidator1 associatedControlvalue1TextBox / label idvalue1Label bindings binding dataContextvalue1TextBox dataPathtext propertytext / /bindings /label /components /page /script 2typeValidator 检测用户输入的数据类型在这个例子中我们验证用户输入的是否为数据
div h3Example 2: Type Validator/h3 br / input typetext idvalue2TextBox classinput / br / br / span idvalidator2 stylecolor:redYou must enter a valid number/span /div 编写Atlas脚本设置非常简单指定type为Number
script typetext/xml-script page xmlns:scripthttp://schemas.microsoft.com/xml-script/2005 components textBox idvalue2TextBox validators requiredFieldValidator errorMessageYou must enter a number. / typeValidator typeNumber errorMessageYou must enter a valid number / /validators /textBox validationErrorLabel idvalidator2 visibilityModeHide associatedControlvalue2TextBox / /components /page /script 3regexValidator 用正则表达式来验证用户输入的数据这里我们以验证用户录入的电话号码格式是否正确为例添加相关的HTML元素
div h3Example 3: RegEx Validator/h3 input typetext idvalue3TextBox classinput / br / br / span idvalidator3 stylecolor: redYou must a valid phone number/span /div 编写Atlas脚本加入regexValidator注意这儿在正则表达式的前后必须加入“/”否则会报脚本错误
script typetext/xml-script page xmlns:scripthttp://schemas.microsoft.com/xml-script/2005 components textBox idvalue3TextBox validators requiredFieldValidator errorMessageYou must enter some text. / regexValidator regex/((d{3,4})|d{3,4}-)?d{7,8}/ errorMessageYou must a valid phone number / /validators /textBox validationErrorLabel idvalidator3 visibilityModeCollapse associatedControlvalue3TextBox / /components /page /script