user3214892
user3214892

Reputation: 147

AngularJS Numbers and Return

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!

Upvotes: 2

Views: 48

Answers (1)

Lajos Veres
Lajos Veres

Reputation: 13725

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.

Upvotes: 2

Related Questions