SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast aliaga61's Avatar
    Join Date
    Sep 2003
    Location
    cincinnati, oh
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form validation check for first part of word

    i want my form to check for a certain word in a login field. if the user enters home/username i want it to yell at them and tell them not to include "home/" when entering their username. i've found all sort of help on form validation for javascript, but none of it talks about checking for a first part of a word. thanks.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">
    
    function checkEntry(oText)
    {
    	var OKArr, entry = oText.value;
    	if (/home\//.test(entry))
    	{
    		alert('i want to yell at you and tell you not to include "home/" when entering your username!!!');
    		OKArr = entry.split('home/');
    		oText.value = OKArr[0] + OKArr[1];
    		oText.focus();
    		return false;
    	}
    }
    
    </script>
    </head>
    <body>
    <form>
    <input type="text" name="username" value=" Enter Username" 
    onclick="if(this.value==this.defaultValue)this.value=''" 
    onkeyup="checkEntry(this)">___username
    </form>
    </body>
    </html>
    ::: certified wild guess :::

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to put a ^ anchor at the beginning.
    ck :: bringing chris to the masses.


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
  •