pub trait IsNumeric {
// Required method
fn is_numeric(&self) -> bool;
}
Expand description
Method to check if the string may be parsed to an integer or float
Required Methods§
Sourcefn is_numeric(&self) -> bool
fn is_numeric(&self) -> bool
strict check on a numeric string before using .parse::<T>()
use trim() or correct_numeric_string() first for looser number validation
This mirrors a similar function in T-SQL, jQuery or the PHP standard library, which is more useful than only checking for digits.
It will fail with spaces or any non-numeric characters other than a leading minus or a single decimal point
For characters, is_numeric checks for decimal digit-equivalent characters
Implementations on Foreign Types§
Source§impl IsNumeric for str
impl IsNumeric for str
Implementation for &str / String
Source§fn is_numeric(&self) -> bool
fn is_numeric(&self) -> bool
Check if the string may be parsed to a number This is a now a strict regex-free check Use trim() or correct_numeric_string() first for looser number validation