Advertisement

04.01.2008 at 10:28AM PDT, ID: 23286553
[x]
Attachment Details

I would like to validate user input string before form is submitted for a comma and space

Asked by deakie in Regular Expressions, JavaScript

Tags: JavaScript Regex, IE

I have a regex to try and confirm that within the user input I have any letter followed by a comma then a space then any letter,
ex: m, a

However it is not working.....Here's the script.
What have I done wrong?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
if (FormAction == 'Search') 
    {		
        var str = document.thisForm.name.value;
        var reg = new RegExp("[a-zA-Z]+,\s?[a-zA-Z]+"); 
 
        if (reg.test(str))
            alert("Format is valid.") 
        else
            alert("Format is invalid.")			
            return;
    }
[+][-]04.01.2008 at 10:36AM PDT, ID: 21256230

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Regular Expressions, JavaScript
Tags: JavaScript Regex, IE
Sign Up Now!
Solution Provided By: ddrudik
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.01.2008 at 10:37AM PDT, ID: 21256242

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.01.2008 at 10:38AM PDT, ID: 21256252

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.01.2008 at 10:46AM PDT, ID: 21256322

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.01.2008 at 10:46AM PDT, ID: 21256329

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628