Click here to Skip to main content
15,891,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I have done
C#
var regExpForInteger = /^[0-9\s]*$/;
           if ($('#totalRowsTextBox').val() < 0 && (!regExpForInteger.test($('#totalRowsTextBox').val()))) {
               alert("Total Rows Column value must be greater than Zero.Only Numbers are Allowed  ");
               return false;
           }
             return True;


But if i put any alphabets ,validation does not work .Please guide me.
I want to allow only integer in my textbox .Alphabets are not allowed.

Thanks in Advance
HArshal
Posted

I am sure you heard about JavaScript isNaN() Function[^]
JavaScript
var f = isNaN($('#totalRowsTextBox').val());

Good luck
 
Share this answer
 
value < 0 and value not a digit can never happen together, so change the && to ||
You regex also accept space \s, it that what you want?
 
Share this answer
 
Comments
R Harshal 29-Jul-14 11:14am    
Thank You peter .
I made a mistake ..
Thanks for your help.
Peter Leow 29-Jul-14 11:27am    
You are welcome.
Peter Leow 30-Jul-14 20:29pm    
What about decimal and negative number?
[no name] 30-Jul-14 1:15am    
Its better to use isNaN method right?
Hi there, you can see this link[^].

Also you can see this link[^].
 
Share this answer
 

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