View Single Post
  #1 (permalink)  
Old Jul 26th, 2007, 14:58
glensimister glensimister is offline
New Member
Join Date: Jul 2007
Location: england
Age: 29
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
help with validation

Hi there!

basically i have built a form and validated the input using regular expressions. When the user enters an invalid entry (onChange) an alert box pops. This works fine. However alert boxes can create problems for visually impaired users who use screen magnification. So what i am trying to do is create an additional error msg at the side of the input box.

similar to the example shown here: http://www.xs4all.nl/~sbpoley/webmatters/formval.html

I attempted many ways of doing this and i cannot seem to get it to work. I have run the code through a javascript varifier so there should not be a typing/spelling errors.

Here is the function:-
Code: Select all
function ValidatePhoneNum()
{
    
    var PhoneNum = document.Form.shipPhoneNumber.value;
    var n = document.getElementById("contactNum");
    var msg=n.nextSibling.nodeValue; //this is the part which seems to be  the issue

var re = /^\d{4}\s*\d{7}|\d{5}\s*\d{6}$/;
    if (!re.test(PhoneNum)) 
    {
            
            alert("Please re-enter Phone number");
            document.Form.shipPhoneNumber.focus();//this does not work either
            msg = "Please re-enter Phone number";            //this will replace "required"
                return false;
     } else {return true;}

}
And here is the html:-
Code: Select all
<td>Contact Telephone Number</td>

                <td id=contactNum><input type="text" name="shipPhoneNumber" maxlength="30" 
                    onChange="return ValidatePhoneNum()"/>Required</td>
If anyone can sugguest a reason why this does not work i would greatly appreciate it.

Thanks!

Last edited by karinne; Jul 26th, 2007 at 15:00. Reason: Please use [ code ]...[ /code ] tags when displaying code!
Reply With Quote