logo

New Response

« Return to the main article

You are replying to:

  1. Back when I didn't really know the object model, I developed this approach to access element values. Thanks to Uri Grinwald for cleaning up my syntax and using the object model to its fullest. In my posting you have to pass the literal field name so quotes are required. Here you pass the field, no quotes: function checkTime(timeV) { var textTime = document.myForm.elements[timeV.name].value; var timeField = document.myForm.elements[timeV.name] var timeExpression =/^(\d{2}):(\d{2})\s{0,1})([AM|PM|am|pm]{2,2}))\W{0}$/; var valresult = textTime.match(timeExpression); if (valresult==null) { alert("Time entry is invalid. Please enter a valid time in hh:mm AM or PM format (e.g. 08:00 AM)"); timeField.value = ""; timeField.focus(); } }

    Notice Uri allows for entry of upper AND lower case AM/am or PM/pm. He is much too kind to his users. Me, I am just giving payback for all those requirements designed for which were never needed.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: