Regular Expression For Validating A String Which Contains Only Characters?
Javascript, Regular Expressions March 8th, 2009Regular expression for validating a string which contains only characters in Javascript?
I assume you mean all alphabet characters (a-z and A-Z) because any string would contain only characters. In Javascript, you can use
var rgx = /^[a-zA-Z]+$/g;
var text_to_validate = new String ("my text to validate");
var result = text_to_validate.search (rgx);
If "my text to validate" contains only alphabet characters, the result would be 0, otherwise (that is, if it contains at least one none-alphabet character), it would be -1.
I hope it has been what you are looking for.