private bool is_number(string str)
{
double num;
return double.TryParse(str, out num);
}
// TRUE
=ISNUMBER(1)
// FALSE
=ISNUMBER("1")
=ISNUMBER("A")
public static boolean isNumeric(String input) {
try {
Double.parseDouble(input);
return true;
}
catch (NumberFormatException e) {
return false;
}
}
...
//true
System.out.println( isNumeric("42") );
System.out.println( isNumeric("3.14") );
System.out.println( isNumeric("1e5") );
// false
System.out.println( isNumeric("A") );
function is_numeric(obj) {
if(obj === '')return false;
if(isNaN(obj))return false;
if(typeof(obj) !== 'number' && typeof(obj) !== 'string')return false;
return true;
}
#define IS_NUMERIC(x) [[NSScanner scannerWithString:x] scanFloat:NULL]
// 1 (YES)
NSLog(@"%d", IS_NUMERIC(@"42"));
NSLog(@"%d", IS_NUMERIC(@"-3.14159"));
NSLog(@"%d", IS_NUMERIC(@"1e5"));
// 0 (NO)
NSLog(@"%d", IS_NUMERIC(@"Hello"));
// true
is_numeric(42);
is_numeric("42");
is_numeric(3.14159);
is_numeric("1e5");
// false
is_numeric("A");
if ($string =~ m/^(\d+\.?\d*|\.\d+)$/){
print "The string matches valid number";
}
' True
IsNumeric(123)
IsNumeric("123")
IsNumeric("42")
IsNumeric("3.14159")
' False
IsNumeric("Hello")
IsNumeric("Hello123")