By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,977 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,977 IT Pros & Developers. It's quick & easy.

Create mask for textbox?

P: n/a
Hi,

I am creating a form in php and one of the fields will be prompting the user
to enter a time in the HH:MM format, is there anyway using php to create an
input mask so it appears as __:__

Or is there a better way to do this?

Many thanks

R
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
RiGGa wrote:
I am creating a form in php and one of the fields will be prompting the user
to enter a time in the HH:MM format, is there anyway using php to create an
input mask so it appears as __:__
No ... well ... almost no, certainly not the way you want it :-)

The HTML form (probably built with PHP):

<form method="POST" action="something">
<!-- ... -->
Enter time in the "HH:MM" format:
<input type="text" name="time" value="__:__" />
<!-- ... -->
</form>

And the script that receives the form:

<?php
/* ... */
$valid_time_input = false;
if (preg_match('/^\d{2}:\d{2}$/', $_POST['time'])) {
if ($_POST['time']{0}*10 + $_POST['time']{1} < 23) {
if ($_POST['time']{3}*10 + $_POST['time']{4} < 60) {
$valid_time_input = true;
}
}
}
if (!$valid_time_input) {
/* wrong input */
/* resend the form, possibly with an error message */
} else {
/* input ok */
/* continue the script */
}
/* ... */
?>
Or is there a better way to do this?


I think you want to do it with JavaScript.
--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Jul 17 '05 #2

P: n/a
Pedro Graca wrote:
RiGGa wrote:
I am creating a form in php and one of the fields will be prompting the
user to enter a time in the HH:MM format, is there anyway using php to
create an input mask so it appears as __:__


No ... well ... almost no, certainly not the way you want it :-)

The HTML form (probably built with PHP):

<form method="POST" action="something">
<!-- ... -->
Enter time in the "HH:MM" format:
<input type="text" name="time" value="__:__" />
<!-- ... -->
</form>

And the script that receives the form:

<?php
/* ... */
$valid_time_input = false;
if (preg_match('/^\d{2}:\d{2}$/', $_POST['time'])) {
if ($_POST['time']{0}*10 + $_POST['time']{1} < 23) {
if ($_POST['time']{3}*10 + $_POST['time']{4} < 60) {
$valid_time_input = true;
}
}
}
if (!$valid_time_input) {
/* wrong input */
/* resend the form, possibly with an error message */
} else {
/* input ok */
/* continue the script */
}
/* ... */
?>
Or is there a better way to do this?


I think you want to do it with JavaScript.

Thanks for the help its appreciated.

R
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.