February 25th, 2010, 06:21 AM
Find exact string length and remove
Hi, how do I validate a string and remove it if it doesn't match the desired length? For example if a phone number is too short or too long, remove it, but if it is the desired length of 11 characters, leave as is?
Thanks in advance
February 25th, 2010, 06:24 AM
You don't need a regular expression for that. Your programming language will have some way of finding the length of a string (e.g. Java's String class has a length() method, Perl has a 'length' function, etc.).
February 25th, 2010, 06:28 AM
You're right Ishnid, I can use my language to check the length, however, I have a group of (pre-built) regexs to remove non-alpha characters, remove spaces etc and I'll like to add to the functionality and make it invisible to my users.
February 25th, 2010, 04:32 PM
After you remove the invalid characters, check the length.
Be warned though that if someone types "123 14th street, new york new york 10036" and you strip out the non-numeric characters, the result will APPEAR to be a phone number, but won't be.
Comments on this post
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.