Help: regular expression: removing white spaces
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Help: regular expression: removing white spaces
I am trying to remove the white space in the 'phone' field, which i am not able to do with the following function:
phone = phone.replace(/^[\s]+/g,"");
You can see the form in action at:
http://www.omnisoft.co.uk/callMeBack.ph ... rmCallBack
phone = phone.replace(/^[\s]+/g,"");
You can see the form in action at:
http://www.omnisoft.co.uk/callMeBack.ph ... rmCallBack
-
Sphen001
- Forum Contributor
- Posts: 107
- Joined: Thu Mar 10, 2005 12:24 pm
- Location: Land of the Beaver
Hi,
Why not just try a simple preg_replace?
Hope this helps 
Sphen001
Hope this helps 
Sphen001one_num = preg_replace(" ", "", $input);
?>
Hope this helps
Sphen001quote;", $input);
?>
Hope this helps
Sphen001; ", "", $input);
?>
Hope this helps
Sphen001t try a simple preg_replace?
Hope this helps 
Sphen001hone_num = preg_replace(" ", "", $input);
?>
Hope this helps
Sphen001(" ", "", $input);
?>
Hope this helps
Sphen0019265a61a00]<?php
$phone_num = preg_replace(" ", "", $input);
?>
Hope this helps
Sphen001pe this helps
Sphen001e preg_replace?
Hope this helps 
Sphen001s
Sphen001t try a simple preg_replace?
Hope this helps 
Sphen001
Hope this helps 
Sphen001]
Hope this helps
Sphen001?
Hope this helps 
Sphen001 helps
Sphen001place(" ", "", $input);
?>
Hope this helps
Sphen001preg_replace?
Hope this helps 
Sphen001t try a simple preg_replace?
Hope this helps 
Sphen001his helps
Sphen001<?php
$phone_num = preg_replace(" ", "", $input);
?>
Hope this helps
Sphen001
Why not just try a simple preg_replace?
Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001
Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001one_num = preg_replace(" ", "", $input);
?>
Hope this helps
Sphen001quote;", $input);
?>
Hope this helps
Sphen001; ", "", $input);
?>
Hope this helps
Sphen001t try a simple preg_replace?
Code: Select all
<?php
$phone_num = preg_replace("e; "e;, "e;"e;, $input);
?&t try a simple preg_replace?Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001hone_num = preg_replace(" ", "", $input);
?>
Hope this helps
Sphen001(" ", "", $input);
?>
Hope this helps
Sphen0019265a61a00]<?php
$phone_num = preg_replace(" ", "", $input);
?>
Hope this helps
Sphen001pe this helps
Sphen001e preg_replace?
Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001s
Sphen001t try a simple preg_replace?
Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001
Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001]
Hope this helps
Sphen001?
Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001 helps
Sphen001place(" ", "", $input);
?>
Hope this helps
Sphen001preg_replace?
Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001t try a simple preg_replace?
Code: Select all
<?php
$phone_num = preg_replace(" ", "", $input);
?>Sphen001his helps
Sphen001<?php
$phone_num = preg_replace(" ", "", $input);
?>
Hope this helps
Sphen001
this is for JS not php.Sphen001 wrote: Why not just try a simple preg_replace?
you could try just putting in a "real" space next to your escaped whitespace.
Code: Select all
phone = phone.replace("e;/ \s*/g"e;,"e;"e;);well I tried a few different things for you and I'm not certain why what you had doens't work. What I posted doesn't work because of the stupid quotes I put in there...but this works just fine
Code: Select all
<!DOCTYPE HTML PUBLIC "e;-//W3C//DTD HTML 4.01 Transitional//EN"e;>
<html>
<head>
<title>Untitled</title>
<script>
function checkIt(){
bobs = document.getElementById("e;bob"e;).value;
alert(bobs);
bobs = bobs.replace(/\s*/,"e;"e;);
alert(bobs);
}
</script>
</head>
<body>
<input type="e;text"e; name="e;bob"e; id="e;bob"e; value="e; hello"e;>
<input type="e;button"e; onclick="e;checkIt()"e;>
</body>- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
http://www.bennadel.com/blog/142-Ask-Be ... Method.htm
Ways without regex
Ways without regex
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: