By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

beginner: how to remove dot's and empty spaces from a number

P: n/a
hello,

i am building a function that checks whether a entered number is a valed
number.

this works fine, but there is a small problem:
- when there is an empty space in the number or when there are
dot's in the number the function does not work properly;

- my question is this: how do i get rid of the empty spaces and/or dot's
when people enter: 12.34.56.789
or when people enter: 12.34 56 789

i want it to change into: 123456789

but i have no idea how to do this,

thanks
Jan 23 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You can do this with using regular expression:

var strNumber = '12.34.56.789';
strNumber = strNumber.replace(/[^\d]/, '');

By the way...

function isNumber(_strValue)
{
return strNumber.match(/^\d+$/) != null;
}

Jan 23 '06 #2

P: n/a
wrote on 23 jan 2006 in comp.lang.javascript:
You can do this with using regular expression:

var strNumber = '12.34.56.789';
strNumber = strNumber.replace(/[^\d]/, '');


1 You need to set global
2 The below \D does it all

strNumber = strNumber.replace(/\D/g, '');
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 23 '06 #3

P: n/a
Evertjan. wrote on 23 jan 2006 in comp.lang.javascript:
wrote on 23 jan 2006 in comp.lang.javascript:
You can do this with using regular expression:

var strNumber = '12.34.56.789';
strNumber = strNumber.replace(/[^\d]/, '');


1 You need to set global
2 The below \D does it all

strNumber = strNumber.replace(/\D/g, '');


and if all white space has to be removed too:

strNumber = strNumber.replace(/[\D\s]/g, '');

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 23 '06 #4

P: n/a
thank you all for your reaction, it is a great help
Jan 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.