public numberOnlyValidation(event: any) { const pattern = /[0-9]/; let inputChar = String.fromCharCode(event.charCode); if (!pattern.test(inputChar)) { event.preventDefault(); } }
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
Hi! Just giving you feedback. Your regexp not only pass numbers but every string containing at least one number.
Take a look at the
^
and$
reserved chars for regexp and think about the floating point your system is using.Something like
^[\d]+$
for only integers.Anyway, you can use isNaN and it's probably a better approach.
developer.mozilla.org/en-US/docs/W...