DelphiFAQ Home Search:
General :: Web publishing :: JavaScript :: Strings


Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Javascript to trim leading 0 (zero) from text input fields

Question:

I need to trim leading 0 (zero) from text input fields

Answer:

Use the Javascript substr() function, or just copy trimNumber() from below.

<script language="JavaScript" type="text/javascript">
 <!--
 function trimNumber(s) {
   while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
   return s;
 }
 
 var s = '00123';
 alert(s + '=' + trimNumber(s));
 
 // end hiding contents -->
</script>
 

Generated 4:02:17 on Mar 26, 2017