Link to home
Start Free TrialLog in
Avatar of HelpNearMe
HelpNearMeFlag for Afghanistan

asked on

jquery ui datepicker validation

Hi Experts,

I'm using a standard Jquery-UI datepicker and I'd like to add validation to the text field because visitors can just type any number in the field.

How can I do this?

Thanks,

HNM
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HelpNearMe

ASKER

leakim971:

Thanks but that doesn't seem to work.  I've attached the form code perhaps you can see where the problem is?

BTW... it's not a jquery data picker like I thought it was.  And I didn't code this page.. I know this page.. it's horrible.  I've been asked to add date validation to it.

Thanks,

HNM
<!-- testing datepicker validation -->
<script type="text/javascript">
    function validate() {
        var dateField = document.getElementsByTagName("wedding_date")[0].value;
        var dateFieldisValid = /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(dateField); // YYYY-MM-DD
        if (!dateFieldisValid) alert("please enter a valid date");
        return dateFieldisValid;
    }
</script>

<!-- end -->


<form action="recibe_form.php" method="post" name="Registro" id="Registro" onsubmit="return validate()">

<table border="0" cellpadding="1" cellspacing="1">

                          <tbody>

                            <tr>

                              <td valign="middle" width="200"><strong> Wedding Date </strong> </td>

                              <td valign="middle"><input name="wedding_date" type="text" id="wedding_date" class="Texto_contenido requerido"  value="" size="10" />

                                    <img src="https://www.logiforms.com/jsimages/calendaricon.gif" alt="3" name="wedding_date_calimage" hspace="4" border="0" id="wedding_date_calimage" /></td>
                            </tr>
                          </tbody>
                        </table>

<input type="submit" class="Texto_titulo_index14Copy" value="Submit" name="Submit" />

</form>

Open in new window

The script is in the <head> section.. and of course all of this is wrapped in relevant body tags etc... the page works, except for the validation.

Thanks!

HNM