(a) Compare field Validator:
Is a Control with compare feature.
Comparing one control with another control.
Properties:
(i) Control to Validate.
(ii) Control to Compare.
(iii) Operator.
(iv) Type.
(v) Error message.
EX:
To compare two Quantities or to compare
any data with another data we use these validators.lets take an
example of comparing two quantities.
|
|
Quantity
|
Text Box1
|
Confirm Quantity Compare Validator.
Text Box2
|
Enter
|
<asp: Compare Validator id=Compare
Validator Control to validate “text Box2”
Control to Compare “Text Box1”Operator
=”Equal” Error Message=”Quantity mismatch”
Type=String Runat=”server”/>
|
Interview Point: Server side
control :-< asp: Text Box id=Text box1 runat=server/>
“asp:”in the above line is Tag
prefix.
“Text Box “is the Tag name.
Syntax: <tag prefix: tag
name<attributes>runat=server/>
|
(b) Control-Value
|
(i) Control to validate.
(ii) Value t Compare.
(iii) Type.
(iv) Operator.
(v) Error message.
(c) Control-Data type
(i) Control to validate.
(ii) Operator data type check.
(iii) Type.
(iv) Error Message.
|
|
Regular Expression Validator
(Post.Pre name)
Mobile expression: - \d-->digits
\d{10}-->digits of 10
\d{1,10}-->between 1
to 10
\d{5,10}-->ranging 5
numbers only
\d{3} -\d{8} (ex: 040-23754526)
\ (A-Z){8}->8 alphabetic
characters are allowed
\ (a-z A-Z){8}-Caps &
Small
Note: Custom validator allows
users to write the logic for validating data and then takes care of displaying
an
error and form submission. Using
custom validator we can perform validation either in client or at server (if
needed both places).client side
means using javascript.And server side means using C#.NET.
Note:
ASP.NET controls perform by
default validations in the client on submission it also perform validation at
server. This is to ensure more
accuracy and also to avoid malfunctioning that may occur during submission of
data.
Custom validator allows user to implement client
side validation using java script.
|
Custom Validator
|
Client side java script
|
Server side java script
|
Client side JavaScript:
(1) Place the custom validator in the form and set the following
properties.
(i) Control to Validate
(ii) Error Message
(iii) Client validate function
(2) Go to ‘source’ view or ‘html’ view
and add script tag to it .inside script tag write “JavaScript” function
with “two parameters” these
two parameters specifies the object and the arguments are passed from control
to function or function to control
using which we can perform our required validations.
<script language=”JavaScript”>
Function f1(x, y).
x-is object.
Y-argument.
{
};
Ex: function check data(x, y)
{
If (y.value>10)
Y.Is Valid=True;
else
Y.Is valid=False;
|
No comments:
Post a Comment