Create mask for textbox?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RiGGa

    Create mask for textbox?

    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
  • Pedro Graca

    #2
    Re: Create mask for textbox?

    RiGGa wrote:[color=blue]
    > 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 __:__[/color]

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

    The HTML form (probably built with PHP):

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

    And the script that receives the form:

    <?php
    /* ... */
    $valid_time_inp ut = 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_inp ut = true;
    }
    }
    }
    if (!$valid_time_i nput) {
    /* wrong input */
    /* resend the form, possibly with an error message */
    } else {
    /* input ok */
    /* continue the script */
    }
    /* ... */
    ?>
    [color=blue]
    > Or is there a better way to do this?[/color]

    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.

    Comment

    • RiGGa

      #3
      Re: Create mask for textbox?

      Pedro Graca wrote:
      [color=blue]
      > RiGGa wrote:[color=green]
      >> 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 __:__[/color]
      >
      > No ... well ... almost no, certainly not the way you want it :-)
      >
      > The HTML form (probably built with PHP):
      >
      > <form method="POST" action="somethi ng">
      > <!-- ... -->
      > Enter time in the "HH:MM" format:
      > <input type="text" name="time" value="__:__" />
      > <!-- ... -->
      > </form>
      >
      > And the script that receives the form:
      >
      > <?php
      > /* ... */
      > $valid_time_inp ut = 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_inp ut = true;
      > }
      > }
      > }
      > if (!$valid_time_i nput) {
      > /* wrong input */
      > /* resend the form, possibly with an error message */
      > } else {
      > /* input ok */
      > /* continue the script */
      > }
      > /* ... */
      > ?>
      >[color=green]
      >> Or is there a better way to do this?[/color]
      >
      > I think you want to do it with JavaScript.[/color]
      Thanks for the help its appreciated.

      R

      Comment

      Working...