Home > Work > Useful JavaScript Function: isInteger and isNumeric #SharePoint #SP2010 #in

Useful JavaScript Function: isInteger and isNumeric #SharePoint #SP2010 #in

Just a quick post as a reminder for myself in future projects.

1 function isNumeric(sText) 2 { 3 var ValidChars = "0123456789."; 4 var IsNumber=true; 5 var Char; 6 7 8 for (i = 0; i < sText.length && IsNumber == true; i++) 9 { 10 Char = sText.charAt(i); 11 if (ValidChars.indexOf(Char) == -1) 12 { 13 IsNumber = false; 14 } 15 } 16 return IsNumber; 17 18 } 19 20 function isInteger(sText) 21 { 22 var ValidChars = "0123456789"; 23 var IsNumber=true; 24 var Char; 25 26 27 for (i = 0; i < sText.length && IsNumber == true; i++) 28 { 29 Char = sText.charAt(i); 30 if (ValidChars.indexOf(Char) == -1) 31 { 32 IsNumber = false; 33 } 34 } 35 return IsNumber; 36 37 } 38

Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: