0

need some help with regex and Jquery.

function cbprValidateUser(username){
    var reg = /^[a-zA-Z'.,-]$/;
    return (reg.test(username));
}

I want to use letters & numbers, no punctuation or spaces

Im rather lost

1

1 Answer 1

1

Your regular expression is wrong. If you want only numbers and letter, use this: ^[a-zA-Z0-9]*

In your case:

function cbprValidateUser(username){
    var username = username || '';
    var reg = /^[a-zA-Z0-9]+$/
    if (reg.test(username)){
        return true; }
    else{
        return false;
    }
}

Btw. this code is pure JavaScript ( no jQuery). Cheers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.