Created
March 4, 2020 21:05
-
-
Save sriramrudraraju/062402269658ebbc8ae4e521c0ee4bf0 to your computer and use it in GitHub Desktop.
Returns only numbers without leading 0s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getOnlyNumbers = (value: string, maxLength?: number) => { | |
// ignores everything except numbers | |
// also ignores leading 0s | |
const filter = value.replace(/[^0-9]+|^0+/, ''); | |
if (maxLength) { | |
return filter.substring(0, maxLength); | |
} | |
return filter; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment