regexp for SSN validation

I have the code below to validate an expression, in this case a name. I need to change the regexp:  regexp: /^[a-z\s]+$/i,
to something that will validate a SSN. I am not familiar with this and I am in sort of a rush to finish this today, help is appreciated.

My current code is below. All I need changed is the regexp.

$(document).ready(function() {
    $('#regexpForm').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            fullName: {
                validators: {
                    regexp: {
                        regexp: /^[a-z\s]+$/i,
                        message: 'The full name can consist of alphabetical characters and spaces only'
                    }
                }
            }
        }
    });
});
</script>

Open in new window


Thank you in advance.
LVL 1
AleksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
Try this for your RegEx

^(\d{3}-?\d{2}-?\d{4}|XXX-XX-XXXX)$

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
I tried the code below but it just allowed anything, letters, etc.

SSN: {
                validators: {
                    regexp: {
                        regexp: ^(\d{3}-?\d{2}-?\d{4}|XXX-XX-XXXX)$ 
                        message: 'The SSN allows numbers and - only'
                    }
                }
            }
        },

Open in new window

plusone3055Commented:
if you want it to strict dashes only   123-45-6789

^\d{3}-\d{2}-\d{4}$
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Dan CraciunIT ConsultantCommented:
I think you need to specify the separators:
regexp: /^(?!000)(?!666)[0-8][0-9]{2}[- ](?!00)[0-9]{2}[- ](?!0000)[0-9]{4}$/

Open in new window

HTH,
Dan
AleksAuthor Commented:
I tried the code below but I can still enter letters no problem.

		SSN: {
                validators: {
                    regexp: {
                        regexp: /^(?!000)(?!666)[0-8][0-9]{2}[- ](?!00)[0-9]{2}[- ](?!0000)[0-9]{4}$/,
                        message: 'Please enter the SSN in the correct format (XXX-XX-XXXX)'
                    }
                }
            }
        },

Open in new window


Same for: ^\d{3}-\d{2}-\d{4}$

IS there a syntax or other problem in the code ?
Dan CraciunIT ConsultantCommented:
That means the regexp is not applied. Probably a JS error. Can you post a link to the page?
AleksAuthor Commented:
Unfortunately no, it is an intranet.
I have other validations inside the same script which work fine :$
Dan CraciunIT ConsultantCommented:
I don't doubt that.
But since the regular expression is correct (check on http://regexpal.com/) then the problem is in the script.

To test, simply use /^[0-9]$/ . It should allow only a single digit.
If it does not work, regular expressions are not your problem, the script is.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.