diaspora/public/javascripts/validation.js
Mark Schmale f5038cdc3c replaced charCode by keyCode. On every browser, keyCode is filled
with the Unicode Character Code when used in keypress.
charCode is only supported in some browsers.
2010-12-13 11:55:54 +01:00

24 lines
619 B
JavaScript

/* Copyright (c) 2010, Diaspora Inc. This file is
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
var Validation = {
rules: {
username: {
characters: /^(|[A-Za-z0-9_]{0,32})$/,
length: [6, 32]
}
},
events: {
usernameKeypress: function(evt) {
if(evt.keyCode === 0) { return; }
if(!Validation.rules.username.characters.test(this.value + String.fromCharCode(evt.keyCode))) {
evt.preventDefault();
}
}
}
};
$(function() {
$("#user_username").keypress(Validation.events.usernameKeypress);
});