[thelist] [Javascript] Form validation with regex

Howard Cheng howcheng at ix.netcom.com
Tue Oct 29 13:59:01 CST 2002


1. $surnamepattern is not a valid Javascript variable name.
2. I would probably use a method on the regex object instead, like:

      if (!surnamepattern.test(surnamefield)) alert("...");

If you want to run it off your string object, you need to use
obj.search(regexObj) instead, and this returns the index position of the
first instance of that pattern (-1 if not found).

At 02:01 PM 10/29/2002 +0000, Garrett Coakley wrote:
>         var surnamepattern = /^[a-zA-Z\-\']+$/;
>         var surnamefield = document.userdetails.surname.value ;
>         function confirmValid() {
>         if ((document.userdetails.surname.value)=="" ||
>         surnamefield.match($surnamepattern)){
>                 alert('Please enter your surname'); return false;
>                 }
>         }

::::::::::::::::::::::::::::::::::
Howard Cheng
http://www.howcheng.com/ <-- NEW!
howcheng at ix dot netcom dot com
AIM: bennyphoebe
ICQ: 47319315




More information about the thelist mailing list