I tend to do a lot of work with database entry through PHP forums. Over time I’ve seen nemorous ways in which someone will enter their phone number.
The Problem
Because there are so many different ways to enter a phone number. How it’s handled, processed and sent to the database becomes a challenge, and as a programmer you have to ask “what is the best way”.
The Solution
The first solution would be to make your column in which will hold the phone number within your database a varchar(20). I suppose for something quick and dirty it will work, but in no means is this efficient.
The second solution would be to take a number:
- (555)555-5555
- 555.555.5555
- 555 555 5555
- 55 55 55 5555
and remove unneeded characters and insert it into the database as a int value of 5555555555
The class:
To use this class:
- Import the class
- Check to ensure there is a number within the field
- Create a new phone validation object and give it a phone number
- Run the validation method within an if statement to ensure it worked.
- If it did call the get method to retrieve the number.
- Close the rest up!
<h3>Validate Phone</h3> <form METHOD=POST ACTION=demo.php> Phone Number: <input type="text" name="phone" maxlength="15" size="15"> <input type="submit" value="submit" name="submit"> </form> <br /> <b>Warning</b>: include_once(Phone.validate.class.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in <b>/home/cnicollo/public_html/wp-content/plugins/php-execution-plugin/includes/class.php_execution.php(273) : eval()'d code</b> on line <b>119</b><br /> <br /> <b>Warning</b>: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Phone.validate.class.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in <b>/home/cnicollo/public_html/wp-content/plugins/php-execution-plugin/includes/class.php_execution.php(273) : eval()'d code</b> on line <b>119</b><br />
Thats just about it. I am open for suggestions or feed back on this snippet.
Write a Comment