Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How to use both JavaScript and ASP.Net Validation controls in parallel ?
Posted
Comments
Dhanamanikandan 12-Apr-12 13:28pm    
what type of validation u need for? post sample example
Dhanamanikandan 12-Apr-12 13:37pm    
Please refer below link for ASP.Net textbox validation with javascript
http://www.daniweb.com/web-development/aspnet/threads/228548/javascript-validation-on-textbox
ZurdoDev 12-Apr-12 15:04pm    
You write the code to do it. Please be more specific.
Sharib Ahmad 14-Apr-12 7:07am    
whom you are asking about the code ?

Hi,

Please find the below code with textbox validation has only numeric value using javascript with aspx textbox.
//Javascript code:
<script type="text/javascript">
    function ValidateCCNum(ccNum) {
                var ccno = ccNum.value;
                if (isNaN(ccno)) {
                    alert("Textbox value should be numeric");
                    ccNum.focus();
                    ccNum.value = null;
                    return false;
                }
                return true;
            }
</script>
</head>

<![CDATA[<%--In Aspx file call this function as below--%>]]>
<asp:content runat="server" id="BodyContent" contentplaceholderid="MainContent" xmlns:asp="#unknown">
 
<asp:textbox id="txtCCDNo" onblur="ValidateCCNum(this)" runat="server"> </asp:textbox>
 
</asp:content>
Run this code in aspx client page
 
Share this answer
 
XML
JS:
<script type="text/javascript" language="javascript">
function validate(sender,args) {
args.IsValid = false;
var tb = document.getElementById('txtInput');
if (args.Value.match(/^\w{6}\d{6}$/)) {
args.IsValid = true
tb.style.backgroundColor = "white";
tb.style.color="green";
}
else {
tb.style.backgroundColor = "red";
}
}
</script>
aspx page:
<asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Button" />
<asp:CustomValidator ID="CustomValidator1"
ControlToValidate="txtInput"
runat="server" ErrorMessage="*"
ClientValidationFunction="validate">
</asp:CustomValidator>
 
Share this answer
 
Comments
Sharib Ahmad 16-Apr-12 7:05am    
Thanks for your help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900