How to show Validation Error in Label Box [Resolved]

Posted by Saranya Boopathi under ASP.NET on 8/21/2012 | Points: 10 | Views : 3039 | Status : [Member] | Replies : 4
in my application
i have a text box if i enter a character i want to dispaly the ErrorValidation in Label box.it allow only number.
using javascript.

Saranya Boopathi


Responses

Posted by: Johnbhatt on: 8/21/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Write this code in Validation Failed Section to assign Value to Label using JavaScript.


function CheckNum()
{
if(document.getElementByID("<%=txtAmount.ClientID%>").value ...........)
{
document.getElementByID("<%=lblStatus.ClientID%>").value="Sorry ! Enter Numbers Only.";
}
}


John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Eni on: 8/21/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
U can try this....using javascript
For example i taken phone number to validate...


if (!IsValidPhone(txtPhone)) {
document.getElementById("lblphn").innerHTML = "*";
return false;
}
else {
document.getElementById("lblphn").innerHTML = "";

}

function IsValidPhone(Phone) {
var phone = /^([0-9])+$/;
return phone.test(Phone)
}


U will get....wt u need think so..

with regards,
eni.


Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/21/2012 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved
Try this,

<script type="text/javascript">
function chkInteger(str) {
var i;
str = str.toString();
for (i = 0; i < str.length; i++) {
var cr = str.charAt(i);
if (isNaN(cr)) {
document.getElementById("lblname").innerHTML = "It allow only number";
return false;
}
}
return true;
}
</script>


<input type="text" name="abc" onkeyup="chkInteger(this.value)"/>
<asp:Label ID="lblname" runat="server" Text="Label"></asp:Label>


Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 8/21/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi, here is the simple code using HTMl.

<html>
<head>
<script type="text/javascript">
function check()
{
var x = document.getElementById("tb").value;
if(x.match(/^[0-9]$/))
{
return true;
}
else
{
document.getElementById("errmsg").innerHTML = "Only Numbers should be entered.";
}
}
</script>
</head>

<body>
<input type="text" id="tb" onblur="check()" />
<label id="errmsg"></label>
</body>
</html>


Regards,

Awesome Coding !! :)

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response