SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Suggesting usename based on domain name

    Hi,

    I'm building a web host order form and I would like to use JS to suggest a username based on the desired domain name. The code would have to, upon leaving the domain name text field, and using the domain name as a basis, convert all characters to lowercase, strip all characters except a-z and 0-9 and then take the 8 first characters and insert them into the username text field.

    I know I've seen something similar somewhere, but I can't remember where. I'm hoping someone else can remember/knows, or perhaps can shed some light onto how I would go about this using an example.

    Thanks in advance !
    Sincerely,

    Eirik Johansen
    Netmaking AS

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not an answer, simply a comment:

    As a valid domain name can only contain characters[A-Za-z0-9] and hyphen, unless you wanted to remove hyphens you'd simply have to base the username on a lower-cased version of the value and take the first eight characters.

    This is assuming that you've already validated the domain name.


    Andy
    From the English nation to a US location.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Agreed. Anyway...
    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">
    
    function suggestUsername(oDomainField, oUserField)
    {
    	var user_name = oDomainField.value;
    	if (/^\s*$/.test(user_name))
    	{
    		alert('Please enter your desired domain name.');
    		oDomainField.focus();
    		oDomainField.select();
    		return false;
    	}
    	user_name = user_name.replace(/[^a-z0-9]/gi, '').toLowerCase();
    	oUserField.value = user_name.substring(0,8);
    }
    
    </script>
    </head>
    <body>
    <pre>
    I'm building a web host order form and I would like to use JS to suggest a username based on the desired domain name.
    The code would have to, upon leaving the domain name text field, and using the domain name as a basis, convert all 
    characters to lowercase, strip all characters except a-z and 0-9 and then take the 8 first characters and insert 
    them into the username text field.
    </pre>
    <form style="font:bold 12px verdana;">
    desired domain name___<input type="text" name="domain_name" value="">
    <br /><br />
    <input type="button" value="get username" onclick="return suggestUsername(domain_name,suggested_username)">
    <br /><br />
    suggested username___<input type="text" name="suggested_username" value="" maxlength="8" readonly="readonly">
    </form>
    </body>
    </html>
    ::: certified wild guess :::

  4. #4
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks you guys, for both the input and the code!
    Sincerely,

    Eirik Johansen
    Netmaking AS


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
  •