user583330
user583330

Reputation: 583

PHONE VALIDATION: How To Overwrite Text In a Textbox When Typing Without Clearing Whole Field?

I would like to know how to create a script that overwrites text that is already in a text box. (in jquery or javascript) Example: If I have a text phone field that says:

+1 (xxx) xxx-xxxx

When a user clicks the field, I want the characters to remain, and the focus set to the 4TH character in the text box, just after the 1.

Then, as a user types each number, it overwrites the x one by one, until all the x's are gone. But, I want the parenthesis and hyphen formatting to stay, so the users input forms around the formatting.

I would also like this form to only allow numbers, hyphens, and parenthesis, and not allow submitting if x's still exist.

If you can help me with this, THANK YOU! :-)

Upvotes: 1

Views: 757

Answers (1)

Chandu
Chandu

Reputation: 82933

Try masked input plugin @ [

http://digitalbush.com/projects/masked-input-plugin/

]1 Looks like it matches what you need.

Upvotes: 3

Related Questions