uwictech Posted October 23, 2009 Share Posted October 23, 2009 Hi all, I would like to set a condition in a txt box that says the number a user enters has to be in the following format ###-#-##-## Would I use PHP to do this or is it part of the HTML form? Jamie Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 23, 2009 Share Posted October 23, 2009 Hi uwictech, Because PHP runs server-side, it would probably be worth investigating a Javascript solution to do this. Have a look at this example which may be of some use. Hope this helps. Quote Link to comment Share on other sites More sharing options...
cbolson Posted October 23, 2009 Share Posted October 23, 2009 I would say that you have 3 choices: 1. - Use javascript to control the format and data type (ie numeric only) 2. - Alternatively you could provide 4 text boxes and set the maxlength on each one accordingly then, when the form is posted, join them up with php. However, you would still need some javascript if you want to only allow them to input numbers. 3. - Finally this could be checked and controlled by php when the form is posted. However, this means that you will have to show the form again if the number is incorrect and prefill all the fields with the data that the user has introduced. Chris Quote Link to comment Share on other sites More sharing options...
uwictech Posted October 27, 2009 Author Share Posted October 27, 2009 OK, thanks for you rinput once again guy's. Jamie Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.