2

is there a way to use AngularJS to only accept Numbers and Return (/n/r) in a textarea? similarly like this:

<textarea>
2344
5335
55555
2222
234
</textarea>

Above is just an example of what I am trying to restrict the text area to. Any suggestions would be great. Thanks!

1 Answer 1

2

https://docs.angularjs.org/api/ng/directive/textarea

Theoretically you can use ngPattern like this:

ngPattern="/[0-9\r\n]*/"

With this setting the textarea will enable anything to type, but treats only numbers and returns as valid.

Probably you can use for example ngChange, to filter out anything non-valid.

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

1 Comment

angularJS does not add a class to the textarea when the pattern is invalid.

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.