Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post

    Is it OK to mix jQuery and JS like this

    This is a simple validation checking for only numbers and letters. It works but I am wondering if it is good practice to mix JS and jQuery in the second "if".

    Code:
    $(document).ready(function() 
    { 
        $('#gloss_search').keydown(function(event)
    	{ 
            if (event.keyCode == 13)
    		{
    			var letterNumber = /^[0-9a-zA-Z]+$/;  
    			if($(this).val().match(letterNumber))   
    			{  
    				alert("Must be a number or letter");
    				//return true;  
    			} 
                return false; 
    		}
    	});
     });

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,636
    Thanks
    6
    Thanked 1,003 Times in 976 Posts
    jQuery is just JS, too. And after all, there is no jQuery equivalent for an alert, simply because it’s not necessary (because it exists in “plain JS” already). Note, however, that alerts should not be used in production code, only for debugging/development.


  •  

    Posting Permissions

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