Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eliminate dashes in text box

Status
Not open for further replies.

ptuck

MIS
Aug 8, 2003
130
US
I have a field the user is inputting their phone number in and I do not want any dashes. How can I remove dashes if they exist or prompt user to reenter without dashes?

Thanks,
Paul
 
Replace() them

Repalce()

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
I am using javascript to validate their are no blanks on the form. Where would I place the Replace() code at and is the following the correct format?

Replace(strPhone, "-", " ") I got an error message when I tried this way (not allowed to use parenthesis when calling a sub), so I tried Replace strPhone, "-", " ". I put this code on my Save.asp page, but I noticed that I only passed -1234 instead of the entire number to this form. Let me know how I am screwing this up.
 
the language of choice was, umm...yeah a bit important of a detail!

value.repalce("-","");

please be a bit more detailed in the future to prevent us telling you the wrong information

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
repalce <-- typo incase not noticed

replace

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
The replace will work fine, though I usually try to avoid the problem all together by creating a separate input for each section of the phone number.

input areaCode
input firstThree
input lastThree

phoneNum = areaCode + firstThree + lastThree

GL
ryandoah
 
The replace will work fine, though I usually try to avoid the problem all together by creating a separate input for each section of the phone number. Using JS to auto-advance.

input areaCode
input firstThree
input lastFour

phoneNum = areaCode + firstThree + lastFour



GL
ryandoah
 
Javascript doesn't replace like asp, if you run a replace on a string it will only replace the first occurence. This is an example using regex to replace all occurences and change the value of the text box before submitting the page

<script language=javascript>
function checkfordashes(){
rExp = /-/gi;
myString=document.myform.phone.value
document.myform.phone.value = myString.replace(rExp, "")
}
</script>

<form name=myform onSubmit="checkfordashes()">
<input type=text name=phone>
<input type=submit>
</form>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top