0

I have some form fields where I only want to allow letters for them to be ('ng-valid'). I have it like the following:

<input type="text" ng-model="Example.field1" ng-pattern="/[a-zA-Z]/" />

It works correctly if you only type in letters, or only type in non-letters, but if they are mixed it won't mark the field as invalid. Can someone tell me why this would be happening? Thanks in advance.

1 Answer 1

1

Try this pattern

/^([A-Za-z]+)$/

Right now you are saying that you want one character anywhere in the string.

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

1 Comment

You are a hero. Thank you.

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.