SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    validation issue

    Hi,

    I am trying to validate a field that is required and also must only contain alphanumeric characters, but I can only get teh required part to work.

    Any ideas what I have wrong?

    This is my code:

    PHP Code:
    function validateForm()
    {
    var 
    x=document.forms["snazzyForm"]["textfield"].value;
    if (
    x==null || x=="")
      {
      
    alert("First name must be filled out");
      return 
    false;
      }
      
    function 
    checkkey(v) {
    if (/\
    W/.test(v.value)) {
    alert("Please enter alphanumerics only");
    return 
    false;
    }
    return 
    true;

      
      

    and

    PHP Code:
    <form  name="snazzyForm" action="index.html" method="POST" onsubmit="return (validateForm() && checkkey(this))">
    <
    input type="text" name="textfield"   />
    </
    form

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    If you indent your code correctly, you'll see that the checkkey function is inside the validateForm function right now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •