Regex not working

I want to add a number only input field along with a maximum length restriction (Prevent user from entering more than the length set, not just throw an error). However, the pattern validation with regex ^[0-9]{1,4}$ is ignored when the input type is set to number