Q:

Form validation allow spaces

In CodeIgniter, for first name last name and all i used validation. It takes only letter without spacing. But I need letter with spaces:
HTML
 <p><label for="FIRST_NAME">First Name</label> <input tabindex="1" size="40" type="text" name="FIRST_NAME" id="FIRST_NAME"/></p> 
 <p><label for="LAST_NAME">Last Name</label> <input tabindex="1" size="40" type="text" name="LAST_NAME" id="LAST_NAME"/></p>

jQuery
function submitForm(){ 

    jQuery.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-z]+$/i.test(value);
    }, "Letters only please");

    var validator = $("#myForm").validate({
        rules: { 
            FIRST_NAME: {
                lettersonly: true,
                required:true
            },
            LAST_NAME: {
                lettersonly: true,
                required:true
    }

Validation is working fine, I just need validation with spaces in field.

A:

Just add a space to your regex
return this.optional(element) || /^[a-z ]+$/i.test(value);
                                       ^

