Skip to main content

Posts

Showing posts with the label jquery

How to generate a valid random mail using Jquery Javascript?

How to generate a valid random mail using Jquery or Javascript In this tutorial we will learn how to generate a random unique email address using Pure Javascript. Use below code it will return a function generateEmail() { var allchars = 'abcdefghijklmnopqrstuvwxyz1234567890'; var emailLength = 15; var string = ''; for(var i=0; i<emailLength; i++){     string += allchars[Math.floor(Math.random() * allchars.length)]; } string = string + '@gmail.com'; return string; } var newEmail = generateEmail(); alert(newEmail); Code Explain: We have created "allchars" variable that contains all possible characters that our function will use, if you want to remove numbers from it or add capital letters , you can edit this string. Then we have defined "emailLength" variable , You can change length of email according tou your requirement. Then we are looping until the length and generating random string using Math functions. Finally we are adding postfix em...

JS HTML REGEX Phone number validation allow 10 digits only

JS jQuery Phone number validation allow 10 digits only If you want to validate an input field where user can input only 10 digits and allow only numeric values then use below code Solutions:- 1) jQuery Allow number upto 10 digits jQuery("#pval").on("keypress keyup blur",function (e) { var thisvallen = jQuery(this).val();    jQuery(this).val(jQuery(this).val().replace(/[^0-9\.]/g,''));       if ((e.which != 46 || jQuery(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {           event.preventDefault();       }         if((thisvallen).length > 10) {             jQuery(this).val((jQuery(this).val()).substr(0,10));             event.preventDefault();         } }); 2) Validate Phone number using JS...

Solution - Hide a div when user clicked outside of it using jQuery

Solution - Hide a div when user clicked outside of it using jQuery If you want to hide an element like listbox, div or dropdown or any html element when click outside of it but not hide when click inside of it then we can do this by using simple jquery code Please use below code to hide an element on outside click. $(document).mouseup(function(e)   {       var containerElem = $("#list-request-suggestion"); //YOUR ELEMENT ID OR CLASS       if (!containerElem.is(e.target) && containerElem.has(e.target).length === 0)       {           containerElem.hide();       }   });   Related Links Hide a div when clicked outside of it How do I detect a click outside an element ? How to hide div on outside click except one inside div through jquery   html - Use jQuery to hide a DIV when the user clicks out...