Databases Reference
In-Depth Information
get { return this.textBox; }
}
protected void Page_Load(object sender, EventArgs e)
{
this.textBox.ToolTip = this.Column.Description;
this.SetUpValidator(this.requiredFieldValidator);
this.SetUpValidator(this.dynamicValidator);
this.SetUpRegexValidator(this.regularExpressionValidator);
}
protected override void ExtractValues(IOrderedDictionary dictionary)
{
dictionary[this.Column.Name] = this.ConvertEditedValue(this.textBox.Text);
}
private void SetUpRegexValidator(RegularExpressionValidator validator)
{
RegularExpressionAttribute attribute = this.Column.Attributes
.OfType<RegularExpressionAttribute>().FirstOrDefault();
if (attribute == null)
{
attribute = new RegularExpressionAttribute(@”\(\d{3}\)\d{3}-\d{4}”);
attribute.ErrorMessage = “The field {0} must be a valid phone number.”;
}
validator.Enabled = true;
validator.Text = “*”;
validator.ValidationExpression = attribute.Pattern;
validator.ErrorMessage = HttpUtility.HtmlEncode(
attribute.FormatErrorMessage(this.Column.DisplayName));
validator.ToolTip = validator.ErrorMessage;
this.IgnoreModelValidationAttribute(attribute.GetType());
}
}
}
Most of the phone number validation in the new field template is performed by the stan-
dard ASP.NET control, RegularExpressionValidator , which ensures that the value entered
by the user matches the regular expression pattern that defines a valid phone number. In
addition to the server-side validation based on the .NET implementation of regular expres-
sions in the System.Text.RegularExpressions namespace, it also works on the client side
taking advantage of the regular expression functionality in JavaScript.
Search WWH ::




Custom Search