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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string manipulation - remove all non #'s

Status
Not open for further replies.

Zych

IS-IT--Management
Apr 3, 2003
313
US
Is there an easy way to remove all non numbers from a string? For example if I have the string "12ed-1234" I would like to get only "121234". In reality the only character that the string can have that is non numeric would be "-" because of a javascript validation I am running. I could remove the "-" but I don't really want to do that at that time. Basically it is asking people to enter there membership ID which is xxxx-xxxx where the x's are numbers 0-9. Some people might include the "-" but some may not. Therefore for comparison I would like to remove it after it is submitted.

Thanks,

Zych
 
In reality the only character that the string can have that is non numeric would be "-" because of a javascript validation I am running.

That is a dangerous assumption. There's someone who has their javascript turned off and send you all kinds of characters. Do not rely solely on client side validation.
 
Thanks. It is working well (at least if javascript is running). As long as I only have numbers though I am OK.

- Zych
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top