Results 1 to 3 of 3

Thread: New to JavaScript

  1. #1
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default New to JavaScript

    Hi,
    I'm New to java Script ,i need to validate some text field,email field,number filed ,give me some advice to do that,any links to refer any ebooks.

    Thanks in advance
    Malick

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Javascript is not the tool for the job in this case. Validation must be performed server-side (although you may wish to do it on the client as well, for convenience).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    I do agree with Twey, but as per request, you can validate a textbox's value if it's a valid email by RegEx:

    HTML Code:
    <script type="text/javascript">
    var ray={
    checkEmail:function(el)
    	{
    	alert(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(this.returnVal(el))?'Congratulations! It\'s a valid email address':'Sorry, it\'s an invalid email address');
    	},
    checkNum:function(el)
    	{
    	// For regex, you can use \d - to test it value is decimal
    	alert(!isNaN(Number(this.returnVal(el)))?'It\'s a valid number':'It\'s an invalid number');
    	},
    returnVal:function(el)
    	{
    	return document.getElementById(el).value;
    	}
    }
    </script>
    <label for="email">Email Address: </label>
    <input type="text" id="email"><br>
    <label for="number">Number: </label>
    <input type="text" id="number"><br>
    <input type="button" value="Validate Email" onclick="ray.checkEmail('email')">
    <input type="button" value="Validate Number" onclick="ray.checkNum('number')">
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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
  •