javascript - How to guess username using email id? -
in registration form taking email id.i want show 3-5 username suggestions using email id.suggestions should relavant email id.
code
var generaterandomusernames = function (email) { var array = []; var possible = email.split('@')[0]; console.log('===========', possible); for( var i=0; < 5; i++ ) array[i] = possible.substring(0,(math.floor(math.random() * possible.length) + 1 )); }
note: email may contain period(.), underscore(_) etc special characters.
could please suggest me how handle special characters contained email?
here example of autocomplete username using email. can modify per requirement.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>auto-complete username using email</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"> <script> $(function() { var emailval = $('input:text[name=email]').val(); var suggestion = emailval.split("@")[0]; var suggestion2=emailval.split(".")[0]; var availabletags = [ suggestion, suggestion2 ]; $( "#tags" ).autocomplete({ source: availabletags }); }); </script> </head> <body> <input type="text" name="email" value="musakkhir.sayyed@gmail.com" /> <div class="ui-widget"> <label for="tags">tags: </label> <input id="tags"> </div> </body> </html>
Comments
Post a Comment