473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Javascript Replace?

I see the use of Javascript replace all over the web. What are all the
character sequences? (sorry I am a bit of a newbie at this).

i.value.replace(/[^\d]+/g, '');

I understand that /g is global and /i is case sensitive, but what are
the rest? I am asking because I am trying to write a function that
takes an input and replaces everything but numbers and a . (for decimal
numbers).

Thanks in advance for your help.

~Brad

Apr 13 '06 #1
3 9200
Hi Brad,

Between the two forward slashes is the meat of the regular expression.

[^\d]+

[^ ] is match any character that is not between the brackets
\d is a digit 0-9
+ means one or more occurances
From your description I think you might want to add "\." to make sure

you don't replace the decimal points.

i.value.replace(/[^\d\.]+/g, '');

but this will jam all the number together because the non numbers are
being replaced with nothing. This might be better.

i.value.replace(/[^\d\.]+/g, ' ');
Peter

Apr 13 '06 #2
Peter,

Thank you for the information. I appreciate it. In acutality, I want
the numbers to be jammed together. I am using this for a numeric only
field.

Apr 13 '06 #3
JRS: In article <11**********************@g10g2000cwb.googlegroups .com>
, dated Thu, 13 Apr 2006 12:31:05 remote, seen in
news:comp.lang.javascript, pe**********@gmail.com posted :
From your description I think you might want to add "\." to make sure

you don't replace the decimal points.

i.value.replace(/[^\d\.]+/g, '');

but this will jam all the number together because the non numbers are
being replaced with nothing. This might be better.

i.value.replace(/[^\d\.]+/g, ' ');


It does, however, break up numbers containing non-whitespace thousands
separators.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.