Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

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 ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Unfortunately no, it is an intranet.
I have other validations inside the same script which work fine :$
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial