locked
Javascript needed RRS feed

  • Question

  • Hi, i need a javascript that turns a this text: 09-444333 or this one (961)- 70-888888 into this format 09444333 and 96170888888 so i want to remove spaces, - , ( and ) from the text.

    How is it feasible?

    Friday, June 13, 2008 8:37 AM

Answers

  • The solution was to put replace(/\(/,"") and .replace(/\)/,"") for the ( and ). becasue the regular expressioon wouldn't take them as characters to replace, it would take them as closing or opening parentheses if we don't put \ before them.

     

    Sunday, June 15, 2008 7:37 AM

All replies

  • You are looking for the Replace function.

     

    Code Snippet

    var tel = crmForm.all.telephone1.DataValue;

    alert(tel.replace(/ /,"").replace(/-/,"").replace(/(/,"").replace(/)/,""));

     

     

     

     

    Jim
    Friday, June 13, 2008 9:43 AM
    Moderator
  •  

    use javascript Replace function or use this

     

    function stringReplace(originalString, findText, replaceText)

    {

    var pos = 0;

    var len = findText.length;

    pos = originalString.indexOf(findText);

    while (pos != -1)

    {

    preString = originalString.substring(0,pos);

    postString = originalString.substring(pos + len,

    originalString.length);

    originalString = preString + replaceText + postString;

    pos = originalString.indexOf(findText);

    }

    return originalString;

    }

     

    Regards,

    Imran

     

    Friday, June 13, 2008 9:55 AM
    Moderator
  • Thanks Jim, Your way worked until now with the space and the - but it didn't work with the ( and the ). I need to know what character to put before them in order to let it work please. thanks

     

    Saturday, June 14, 2008 7:36 AM
  • The solution was to put replace(/\(/,"") and .replace(/\)/,"") for the ( and ). becasue the regular expressioon wouldn't take them as characters to replace, it would take them as closing or opening parentheses if we don't put \ before them.

     

    Sunday, June 15, 2008 7:37 AM