1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-12 11:28:56 +00:00
trezor-wallet/src/utils/validators.js

28 lines
743 B
JavaScript
Raw Normal View History

2019-04-22 09:31:55 +00:00
/* @flow */
export const hasUppercase = (value: string) => {
const UPPERCASE_RE = new RegExp('^(.*[A-Z].*)$');
return UPPERCASE_RE.test(value);
};
2019-04-22 11:43:44 +00:00
export const hasDecimals = (value: string, decimals: number) => {
2019-04-22 09:31:55 +00:00
if (decimals === 0) {
return isAbs(value);
}
2019-04-22 11:46:19 +00:00
const ETH_DECIMALS_RE = new RegExp(
2019-04-22 09:31:55 +00:00
`^(0|0\\.([0-9]{0,${decimals}})?|[1-9][0-9]*\\.?([0-9]{0,${decimals}})?)$`
);
2019-04-22 11:46:19 +00:00
return ETH_DECIMALS_RE.test(value);
2019-04-22 09:31:55 +00:00
};
export const isAbs = (value: string) => {
const ABS_RE = new RegExp('^[0-9]+$');
return ABS_RE.test(value);
};
2019-04-22 11:43:44 +00:00
export const isNumber = (value: string) => {
2019-04-22 11:46:19 +00:00
const NUMBER_RE = new RegExp(`^(0|0\\.([0-9]+)?|[1-9][0-9]*\\.?([0-9]+)?)$`);
return NUMBER_RE.test(value);
2019-04-22 09:31:55 +00:00
};