Alphabets validation using javascript and php

What is the regular exprn to validate alphabets including space character

The code below gives validate names like ‘Anjana’

When i enter a name like ‘anjana menon’ its not validating…

var txtname=document.getElementById(“txt_name”).value;

var filter=/[1]+$/;
var test_bool = filter.test(txtname);
if(test_bool==false)
{
alert(‘Please Enter Only Alphabets in the Name Field’);
document.getElementById(“txt_name”).focus();
return false;
}

Pls help…:injured:


  1. a-zA-Z ↩︎

var filter=/^[a-z ]+$/i;

or

var filter=/^[\\w ]+$/i;

make sure to keep space before ] in that expression.


var filter=/^[\\w\\s]+$/;

Note that the ‘only alphabets in name’ validation may result in John O’Connor or Sean O’Shea getting rejected.

The JavaScript Form Validation script and [URL=“http://www.html-form-guide.com/php-form/php-form-validation.html”]PHP form validation script can make validations easier