Category Archives: Javascript
- September 28, 2006
- Javascript parseInt() quirk
I ran into a little quirk or ‘bug’ today when using parseInt() with a string (input from a text box). Now as we all know parseInt() parses a string and returns an integer value.
The scenario: I was working on a legacy application where a user could pass a date to the server in 3 separate [...]
- September 19, 2006
- Trimming strings with Javascript
Ben Nadel has a nice post on trimming strings with javascript using regular expressions.
Note that the reg exp white space character ‘\s’ is used to match:space
tab
horizontal tab
vertical tab
line breakSample code below:
<script type="text/javascript">// Trims the beginning and trailing white space from a string.
function trim( strText ){
return( strText.replace(new RegExp("^([s]+)|([s]+)$", "gm"), "") );
}// Trims the beinning white space [...]
