Validation to accept only numbers!!!
-
Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh
-
Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh
Well, you should change the ValidationExpression to accept more than one character. Also, decide whether you will accept +/- sign before the number, decimal point etc. Than build proper regular expression and that's it. I strongly recommend to read a little about "creating regular expression" on the MSDN. And to make it works, and accept any number of digits modify ValidationExpression to "[0-9]*".
-- Mariusz 'mAv' Wójcik master e-software engineer
-
Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh
include * in your validation expression either at the begining or at the end.
-
Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh
hello ramesh, try to use the following code in Javascript function CkhInte(obj) { if (isNaN(obj.value)) { alert('Please enter only digits'); return false; } } hope it helps, please rate this message if useful, best regards, koolprasad2003:)
Be a good listener...Because Opprtunity knoughts softly...N-Joy
-
Hi all, i have to validate for a textbox field in ASP.NET 2.0 using C#. the requirement is that the textfield should accept only numbers. i want the field such tat it should accept number..... any number of any length..... please send me the code for the same...... the regular expression validator with the validation expression ValidationExpression="[0-9]" accepts only a single digit number......... how do i make it accept any number!!!!!!! Thanks, Ramesh
ValidationExpression="^\d+$" the above expression is a regular expression validator to validate for numbers......
-
hello ramesh, try to use the following code in Javascript function CkhInte(obj) { if (isNaN(obj.value)) { alert('Please enter only digits'); return false; } } hope it helps, please rate this message if useful, best regards, koolprasad2003:)
Be a good listener...Because Opprtunity knoughts softly...N-Joy
Nice, but when user turn off javascript in browser it will allow him to enter incorrect input. It's necessary to do the same validation on server. ASP.NET validators do both for you.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe