Showing posts with label Validation. Show all posts
Showing posts with label Validation. Show all posts

Saturday, May 10, 2014

JQuery Allow specific number of Alphabets into text box in asp.net

Title:Allow only number of Alphabets in to Text box in asp.net using JQuery

Description:
As per previous article ,we have done validation on the text box which has to hold some value while doing the insertion.Now i would like describe and give an example on JQuery validation ,which will allow only 10 characters into text box.So here i will put condition text box length while performing the validation i:e is less then 10 ,it will show error message through alert box

Example:
<html>
<head runat="server">
<script type="text/javascript" src="Javascript/jquery-1.3.1.min.js"></script>
<script type="text/javascript" language="javascript">

$(document).ready(function() {

$('#allowOnlyChars').click(function() {

if ($("#OnlyChars").val().length < 10) {

alert('Valid data'+"#OnlyChars").val());

return true
}
else {
alert('Please: you should enter only 10 characters')
return false;
}
})
});
</script>
</head>
<body>
<form id="validateForm" runat="server">
<asp:TextBox ID="OnlyChars" runat="server"></asp:TextBox>
<asp:Button ID="allowOnlyChars" runat="server" Text="Validate" OnClick="allowOnlyChars_Click" />
</form>
</body>
</html>

Monday, April 28, 2014

JQuery validate textbox in asp.net


Title : How to validate text box using JQuery in asp.net

Description : Why we have to apply validation on input control?Because of this functionality we can restrict the input data as per our need.Now we will see how to do the validation using client side script(JQuery).If we want to develop the validations in asp.net we have to use validation 
control for specified control.

Example:
<html>
<head runat="server">
<script type="text/javascript" src="Javascript/jquery-1.4.1.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$('#doValidate').click(function() {
if ($("#allowData").val()!="") {
alert('Enter Text'+"#allowData").val());
return true
}
else {
alert('Please enter valid data')
return false;
}
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="allowData" runat="server"></asp:TextBox>
<asp:Button ID="doValidate" runat="server" Text="Validate" OnClick="doValidate_Click" />
</form>
</body>
</html>


Friday, April 26, 2013

Asp.net validation controls

Title:How to use validation control in asp.net

Description:
Normally in web application, validation are perform using java script. We must write JS and perform validations.If validations are successful then we redirect the user to sever and if validation fails then we display error to user to perform all these with java script. It is complex and also time consuming.In previous articles i explained how to pass server side variable to client side in asp.net,Validate drop down list in java script,How to validate text box in JQuery

Asp.net developers are provided with validation controls which enable user to perform validation just like server side controls.These validation controls render Jquery to the client or browser like this we can have rapid application development for validation and also we can reduce the Complexity of writing java script code validation controls of asp.net target clients as automatic which means based on browser validation are perform

The fallowing validation controls are supported by asp.net
1.Required Field validator
2.Range validator
3.Compare validator
4.Regular expression validator
5.Custom validator
6.Dynamic validator
7.validation summary

The most common property for validation controls:
Controltovalidate:web control id
Error message =message
setFoucsError=true/false
validation Group :makes the control part of separate validation group
Display:static(default)/dynamic/none
i.static :Initially place for displaying error will be reserved.When error occurs it will be visible otherwise it will be hidden
ii.Dynamic:No place in the form will be reserved initially only on error dynamically the message will be shown
iii.none:will not display the error message only

Required field validator:

Used to check null values and it is the only control that checks null values .Remaining validation controls doesn't perform any validation if null values are entered.IN the below example have used this validation for Textbox(txtOrder) which is used to give the Order value.
<asp:requiredfieldvalidator controltovalidate="txtOrder" display="dynamic" errormessage="Enter Order Details" id="RfOrder" runat="server">* 
</asp:requiredfieldvalidator>

Range validator:

To check for range of values.Useful for numeric and date format of data Additional properties Minimum value :1
maximum Value :1000

<asp:textbox id=" runat="server" txtage=""> <asp:RangeValidator id="RvAge" runat="server" ControlToValidate="txtage" 
 MaximumValue="16" 
 MinimumValue="24" 
 Type="Integer" 
 ErrorMessage="Enter valid age" Display="Dynamic">*</asp:RangeValidator>
Can one control have multiple validation controls? the answers is yes
we can use one validation control validate single controls only

Compare validator:

With compare validation we can perform 3 types of validation all will be based on comparison
1.Control with another control
2.control with value
3.control with data type

 UserName<asp:textbox id="txtuser1" runat="server"/>
 Reenter UserName: <asp:textbox id="txtuser2" runat="server"/>

<asp:CompareValidator ControlToValidate="txtuser1" ControlToCompare="txtuser2" Operator="Equals" ErrorMessage="Please enter valid user name" Display="dynamic">*</asp:CompareValidator>

validation summary control:

Used to report errors as a summary i:e display all control errors.error message display throw summary control.It has two properties
i)show summary :true/false
ii)show messageBox =true/false
when display is set to none then validation control will not display error in its place instead if displays error in summary control .

Regular expression validator:

Using they control we can specify on expression and ask validator to match the expression with control.Previously i have given to validate email using regular expression in asp.net.

Custom validator:

In previous post i have given example on how to use custom validator in asp.net.For complete details click here

Thursday, December 20, 2012

Jquery Dropdownlist validation in asp.net

Title: JQuery How to validate Drop Down List value  in asp.net

Description:
Recently i have worked drop down list data validation using JQuery. Now i would like to explain how to validate the data of drop down list using JQuery .In previous articles i have given an example on Jquery drop down validation,JQuery allow only numbers.Here in this post i will given script for Validate DropdownList Using JQuery
Example:
   $(document).ready(function () {
    $('#btnsubmit').click(function(){
        cntydr = $('#ddlcountry');
        if (cntydr.length == 0 || $(cntydr).val() == "") {
            alert("Please Choose Country");
        }
        });
    });
As you can see the below screen shots to know the how they will get validation  conformation on page
In the above script i have used button click event to perform the validation.So when ever we click on the submit button the validations will be done.

Monday, August 20, 2012

Java script validation on Server side in asp.net

Title:Java script validation in asp.net

Description :
As per previous articles,we discussed on java script validation on client side in asp.net .Now i would like give an example on validation which can be done on server side.In the below example i have used a web server control (Text box size) which should contain 30 characters with specified text format
Example:

if (TxtFormate.Text == "")
{
ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('Enter Format');</script>");
TxtFormate.Focus();
return;
}
if (int.Parse(TxtFormate.Text.Length.ToString()) > 30)
{
ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('Allows only 0 to 30 Characters');</script>");
TxtFormate.Focus();
return;
}

Bel