1749 posts
  • 4 Years of Membership
  • Beta Tester
  • Collector Level 2
  • Exclusive Author
webdesignerart
says

Hi friends,

I am using javasrcript for string replacement,

i m currently doing replace.(string,tothisstring)

i have a regex for valid north American phone number here it is:
var regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;

its check valid phone number like (800)123 1234, 800.123.1456 etc etc formats.

i want to replace (800)123 1234 to (800)123 1234

i dont know $1 to $2 replacement.

friends did you have any solution for it.

5492 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Australia
  • Author Level 3
+5 more
Australia
says

Hi friends,

I am using javasrcript for string replacement,

i m currently doing replace.(string,tothisstring)

i have a regex for valid north American phone number here it is:
var regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;

its check valid phone number like (800)123 1234, 800.123.1456 etc etc formats.

i want to replace (800)123 1234 to (800)123 1234

i dont know $1 to $2 replacement.

friends did you have any solution for it.

Arent:

i want to replace (800)123 1234 to (800)123 1234

The same ??

1749 posts
  • 4 Years of Membership
  • Beta Tester
  • Collector Level 2
  • Exclusive Author
webdesignerart
says

i wanted replace or add HTML element span tag to (800)123 4587

means (800)123 4587 to (800)123 4587

1749 posts
  • 4 Years of Membership
  • Beta Tester
  • Collector Level 2
  • Exclusive Author
webdesignerart
says
here is function i am using:
var avidno = '1234567890';
function validate () {
    var regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;

   if (regex.test(avidno)) {
        alert('bingo');
        var altrstr = avidno.replace(regex, ' <span>$2</span>');
        alert(altrstr);
        // Valid international phone number
    } else {
        alert('uupss');
        // Invalid international phone number
    }
}

validate();

i want regex that replace or add span before and after 12345678 to 123546789

1141 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 6
  • Collector Level 4
+3 more
KarmaThemes
says

i want regex that replace or add span before and after 12345678 to 123546789

The two numbers are the same, in case you are using some tags, the forum doesn’t display them. It’s not easy to guess what you possibly mean :)

5492 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Australia
  • Author Level 3
+5 more
Australia
says

Always easier to create a fiddle

http://jsfiddle.net/
5441 posts
  • Author Level 11
  • Moderator
  • Winner
  • 6 Years of Membership
+20 more
dtbaker
Moderator
says

he typed

(800)123 4587 to <span>(800)123 4587</span>
5492 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Australia
  • Author Level 3
+5 more
Australia
says

Ok then use this tool.

http://regex.larsolavtorvik.com/
1749 posts
  • 4 Years of Membership
  • Beta Tester
  • Collector Level 2
  • Exclusive Author
webdesignerart
says
firennnndddddddsssssss its my mistake if forget that when posting html elements in forum add
 <span>tag before and after </span>

friends here is my exact code:


var avidno = '1234567890';
function validate () {
    var regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;

   if (regex.test(avidno)) {
        alert('bingo');
        var altrstr = avidno.replace(regex, ' <span>$2</span>');
        alert(altrstr);
        // Valid international phone number
    } else {
        alert('uupss');
        // Invalid international phone number
    }
}

validate();

i want to replace number(800)123 45678 to

<span>(800)123 4587</span>

Basically i want to add

<span>mynumber</span>
before and after to the number :)

1749 posts
  • 4 Years of Membership
  • Beta Tester
  • Collector Level 2
  • Exclusive Author
webdesignerart
says

ANy one here! to help me.

by
by
by
by
by
by