An improved isNumeric() function?

In my opinion, if it’s an array then its not numeric. To alleviate this problem, I added a check to discount arrays from the logic You can have that problem with any other object as well, for example {toString:function(){return “1.2”;}}. Which objects would you think were numeric? Number objects? None? Instead of trying to blacklist … Read more

How do you test your Request.QueryString[] variables?

Below is an extension method that will allow you to write code like this: int id = request.QueryString.GetValue<int>(“id”); DateTime date = request.QueryString.GetValue<DateTime>(“date”); It makes use of TypeDescriptor to perform the conversion. Based on your needs, you could add an overload which takes a default value instead of throwing an exception: public static T GetValue<T>(this NameValueCollection … Read more

Checking if string is numeric in dart

This can be simpliefied a bit void main(args) { print(isNumeric(null)); print(isNumeric(”)); print(isNumeric(‘x’)); print(isNumeric(‘123x’)); print(isNumeric(‘123’)); print(isNumeric(‘+123’)); print(isNumeric(‘123.456’)); print(isNumeric(‘1,234.567’)); print(isNumeric(‘1.234,567’)); print(isNumeric(‘-123’)); print(isNumeric(‘INFINITY’)); print(isNumeric(double.INFINITY.toString())); // ‘Infinity’ print(isNumeric(double.NAN.toString())); print(isNumeric(‘0x123’)); } bool isNumeric(String s) { if(s == null) { return false; } return double.parse(s, (e) => null) != null; } false // null false // ” false // ‘x’ false … Read more

jQuery: what is the best way to restrict “number”-only input for textboxes? (allow decimal points)

If you want to restrict input (as opposed to validation), you could work with the key events. something like this: <input type=”text” class=”numbersOnly” value=”” /> And: jQuery(‘.numbersOnly’).keyup(function () { this.value = this.value.replace(/[^0-9\.]/g,”); }); This immediately lets the user know that they can’t enter alpha characters, etc. rather than later during the validation phase. You’ll still … Read more

Identify if a string is a number

int n; bool isNumeric = int.TryParse(“123”, out n); Update As of C# 7: var isNumeric = int.TryParse(“123”, out int n); or if you don’t need the number you can discard the out parameter var isNumeric = int.TryParse(“123”, out _); The var s can be replaced by their respective types!

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)