Validation to accept only numbers!!!
-
Hi all, Is there any specific property or control in ASP.NET 2.0 using which i can enter only numerical characters in a textbox?? How do i do this??? If no, please semd me the piece of code using which i can do this validation. Thanks Ramesh
-
Hi all, Is there any specific property or control in ASP.NET 2.0 using which i can enter only numerical characters in a textbox?? How do i do this??? If no, please semd me the piece of code using which i can do this validation. Thanks Ramesh
//here formElement is the control and myString is the string typed into it . //By using this javascripting code the characters and others will not //get //typed only numbers will type. function removeInvalidChars(formElement, myString) { var intPeriod = 0 for (var i = 0; i < myString.length; i++) { A_char = myString.charCodeAt(i) //We are validating for numbers. if (A_char > 47 && A_char < 58) { // It's a number continue; } else { myString = myString.substring(0,i) } } formElement.value = myString; }
-
Hi all, Is there any specific property or control in ASP.NET 2.0 using which i can enter only numerical characters in a textbox?? How do i do this??? If no, please semd me the piece of code using which i can do this validation. Thanks Ramesh
you can use regular expression validation like this: ""asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Numeric Value" ControlToValidate="TextBox1" ValidationExpression="[0-9]">Raghvendra Kumar Roy
-
Hi all, Is there any specific property or control in ASP.NET 2.0 using which i can enter only numerical characters in a textbox?? How do i do this??? If no, please semd me the piece of code using which i can do this validation. Thanks Ramesh
This script is used for u accept only numbers.
function isinteg(obj){ if (isNaN(obj.value)){ obj.value=""; return false; } return true; }
Regards, Satips.:rose:
-
Hi all, Is there any specific property or control in ASP.NET 2.0 using which i can enter only numerical characters in a textbox?? How do i do this??? If no, please semd me the piece of code using which i can do this validation. Thanks Ramesh
function intOnly(obj) { if(obj.value!=parseInt(obj.value)) { alert("Please Enter Whole Number only"); obj.value=""; } } i hope this will help you. Puneet Srivastava
-
you can use regular expression validation like this: ""asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Numeric Value" ControlToValidate="TextBox1" ValidationExpression="[0-9]">Raghvendra Kumar Roy
Hi Raghav, Thanks! n wat do i do if i want to validate a filed called year which should accept only 4 digit year like 2007 and not 07. also i want a textbox which should not accept special characters.
-
Hi Raghav, Thanks! n wat do i do if i want to validate a filed called year which should accept only 4 digit year like 2007 and not 07. also i want a textbox which should not accept special characters.
if you want to validate a filed called year which should accept only 4 digit year like 2007 and not 07. try this: After validationexpression you can define numbers Just add this for your problem ValidationExpression="[0-9]{4}" if you want a textbox which should not accept special characters. it will accept only uppercase characters,lowercase characters and numeric characters. ValidationExpression="[A-Z,a-z][0-9]" Thanks
Raghvendra Kumar Roy
-
Hi all, Is there any specific property or control in ASP.NET 2.0 using which i can enter only numerical characters in a textbox?? How do i do this??? If no, please semd me the piece of code using which i can do this validation. Thanks Ramesh
Public Class Form2 Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim c As Integer c = Asc(e.KeyChar) If c = 8 Or c = 13 Then Exit Sub ElseIf c < 47 Or c > 57 Then e.Handled = True ErrorProvider1.SetError(TextBox1, "Invalid Number") Else e.Handled = False ErrorProvider1.SetError(TextBox1, "") End If End Sub End Class just create a user control and use it wherever u want
-
you can use regular expression validation like this: ""asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Numeric Value" ControlToValidate="TextBox1" ValidationExpression="[0-9]">Raghvendra Kumar Roy
hey raghav...... this accepts only a single digit number!!!! i want the field such tat it should accept number..... any number of any length..... but this validation coontrol accepts only a single digit no. not any other number also please help asap. thanks Ramesh
-
hey raghav...... this accepts only a single digit number!!!! i want the field such tat it should accept number..... any number of any length..... but this validation coontrol accepts only a single digit no. not any other number also please help asap. thanks Ramesh
Hey Ramesh Try this: ValidationExpression="[0-9]*$"
Raghvendra Kumar Roy
-
Hey Ramesh Try this: ValidationExpression="[0-9]*$"
Raghvendra Kumar Roy
Hey Raghav, I have been able to do it by simply adding a star ValidationExpression="[0-9]*" For wat is tat additional $ ? Please let me know
-
Hey Raghav, I have been able to do it by simply adding a star ValidationExpression="[0-9]*" For wat is tat additional $ ? Please let me know
hi Ramesh $ means stop looking at this position.
Raghvendra Kumar Roy