jQuery Validator : Validate AlphaNumeric + Space and Dash
working demo http://jsfiddle.net/cAADx/
/^[a-z0-9\-\s]+$/i
should do the trick!
g = /g modifier makes sure that all occurrences of "replacement"
i = /i makes the regex match case insensitive.
good read: http://www.regular-expressions.info/javascript.html
Hope this helps,
code
$(function() { $.validator.addMethod("loginRegex", function(value, element) { return this.optional(element) || /^[a-z0-9\-\s]+$/i.test(value); }, "Username must contain only letters, numbers, or dashes."); $("#myForm").validate({ rules: { "login": { required: true, loginRegex: true, } }, messages: { "login": { required: "You must enter a login name", loginRegex: "Login format not valid" } } });});
Will remove this image in 2 mins see here robert like this http://jsfiddle.net/5ykup/