With all due respect, I think karl's solution is somewhat less than
elegant, and could be improved by refactoring to:

// test for anything but numbers
var isValid = /[^\d]/g.test(textareaValString);

if (isValid) {
    // proceed with confidence
} else {
    // note to user: no numbers allowed!
}

On Aug 8, 11:13 pm, Karl Swedberg <k...@englishrules.com> wrote:
> On Aug 7, 2009, at 2:53 PM, Michael Lawson wrote:
>
> > yes, you can grab the value of the textbox and match it against a  
> > regular expression
> > var reg = new RegExp("/[a-zA-Z]/");
> > if(reg.test("string"))
> > {
> > return "valid";
> > }
> > else
> > {
> > return "not valid";
> > }
>
> Hey Michael,
>
> I don't think that regular expression is going to work. If you're  
> using a regular expression constructor method, as opposed to a  
> literal, you shouldn't use the slashes. Even without the slashes, that  
> test will always return true as long as the string has one upper or  
> lower case letter from a to z.
>
> The OP wanted to disallow numbers, so this should do it:
>
> if ( !(/\d/).test("string") ) {
>    return 'valid';} else {
>
>    return 'not valid';
>
> }
>
> --Karl
>
> ____________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com

Reply via email to