ASP.NET : Custom Validator

Custom Validator
Checks the user's entry using validation logic that you write yourself. This type of validation enables you to check for values derived at run time.

Properties

ClientValidationFunction: Which JavaScript function that you want to check.

Example

1. Create a ASP.NET website then add Standard TextBox and CustomValidator.
2. Create your JavaScript Function for validate (For this example will check about input digits).

        <! Example !!>
        <head> <title>Test Validate</title>

        <script language="JavaScript">
           function checkDigit(source, agrs) {
               if(agrs.Value.length < 8 || agrs.Value.length > 12
                   args.IsValid = false;
               else
                   args.IsValid = true;
           }
        </script></head> 

3. Select your CustomValidator and set require properties for validate (see Table 1).



PropertiesValue
ClientValidationFunctioncheckDigit
ControlToValidateTextBox1
ErrorMassagePlease input 8-12 characters

Table 1: Require Properties for CustomValidator

4. Test your application you will see error message when you input wrong condition (Figure 1).


Figure 1: Custom Check  Example

##############################

CompareValidator (Check Data Type) << Previous Chapter || Next Chapter >> RangeValidator

ASP.NET : CompareValidator (Check Data Type)

Compare Validator
Compare a specify data type or Compare a user's entry value between two controls.

Properties (Data Type Checked)
Operator : Choose "DataTypeCheck"
Type : Which Data Type that you want to check.

Example Data Type Checked
1. Create a ASP.NET website then add Standard TextBox and CompareValidator.
2. Select your CompareValidator and set require properties for validate (see Table 1).


PropertiesValue
ControlToValidateTextBox1
ErrorMassageWrong !!
OperatorDataTypeCheck
TypeInteger

Table 1: Require Properties for Compare

3. Test your application you will see error message when you input wrong data type (Figure 1).



Figure 1: Data Type Check  Example


##############################

CompareValidator (Check Equal) << Previous Chapter || Next Chapter >> CustomValidator

JavaScript : Array Object [2/2]

Method Name
Description
concat() Joins two or more arrays, and returns a copy of the joined arrays
join() Joins all elements of an array into a string
pop() Removes the last element of an array, and returns that element
push() Adds new elements to the end of an array, and returns the new length
reverse() Reverses the order of the elements in an array
shift() Removes the first element of an array, and returns that element
slice() Selects a part of an array, and returns the new array
sort() Sorts the elements of an array
splice() Adds/Removes elements from an array
toString() Converts an array to a string, and returns the result
unshift() Adds new elements to the beginning of an array, and returns the new length
valueOf() Returns the primitive value of an array

Example concat()
   var color1 = ["Red", "Green"];
   var color2 = ["Blue", "Yellow"];
   var color3 = ["Black"];
   var color = color1.concat(color2,color3);
   document.write(color);

Example pop()
   var fruits = ["Banana", "Orange", "Apple", "Mango"];
   document.write(fruits.pop() + "<br/>");
   document.write(fruits);


Example sort()
   var ele = ["Dark", "Water", "Fire", "Holy"];
   document.write(ele.sort());

Example sort() (Number)
   function sortNumberASC(a,b) {
       return a - b;
   }
   function sortNumberDESC(a,b) {
       return a - b;
   }
   var n = ["30", "19", "50", "7"];
   document.write(n.sort(sortNumberASC));                                            
   document.write(n.sort(sortNumberDESC));

##############################

JavaScript : Array Object [1/2] << Previous Chapter

Related Posts Plugin for WordPress, Blogger...