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 Link to comment https://forums.phpfreaks.com/topic/178714-solved-setting-condidtions-for-an-input-box/ 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. Link to comment https://forums.phpfreaks.com/topic/178714-solved-setting-condidtions-for-an-input-box/#findComment-942718 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 Link to comment https://forums.phpfreaks.com/topic/178714-solved-setting-condidtions-for-an-input-box/#findComment-942720 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 Link to comment https://forums.phpfreaks.com/topic/178714-solved-setting-condidtions-for-an-input-box/#findComment-945258 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.