This tutorial will allow you to prevent usernames that contain numbers at registration, as in the example below.
Setting up
Go to Administration Panel > Modules > JavaScript Codes management and create a new script.
Title : Your choice Placement : In all the pages
Code:
location.pathname=="/register" && location.search=="?agreed=true&step=2" && $(function(){ Â Â Â Â Â var username_format = /^[^0-9]*$/; Â var format_notice = "Numbers are not allowed in usernames"; Â Â Â Â Â var f = $('form[action=""][method="post"]'); Â var p = $('#username_reg'); Â var i = $('<span id="username_issue" />').html('<br/>'+format_notice).css({ "color":"red", "font-style":"italic", "display":"none"}).appendTo(p.parent()); Â Â Â Â Â var u = function() { Â Â if (username_format.test(p.val())) i.hide(); Â Â else { Â Â Â i.show(); Â Â Â return false; Â Â } Â }; Â Â Â Â Â p.on('change keyup', function(){ u() }); Â $('input[type="reset"]', f).click(function(){ u() }); Â $('input[type="submit"]', f).click(u); Â u(); Â Â Â Â });
Variants
The script uses a regular expression( /^[^0-9]*$/ ) to detect if the username contains a digit.
Here are a few websites with tutorials on regular expressions :