[Original] Use the regular expression to verify whether the input is a number in C # .NET

xiaoxiao2021-03-06  56

Author: bluesky35 (blue) directly call the following function to test the return value of true indicates that the input is a number, not vice versa. ItemValue is the value input. Using System.Text.RegularExpressions; Private Static Bool IsNuMeric (String ItemValue) {Return (IsRegex ("^ (-? [0-9] * [.] * [0-9] {0,3}) $", itemValue ));

Private Static Bool IsRegex (String ItemValue) {

try {Regex regex = new System.Text.RegularExpressions.Regex (regExValue); if (regex.IsMatch (itemValue)) return true; else return false;} catch (Exception) {return false;} finally {}}

转载请注明原文地址:https://www.9cbs.com/read-113855.html

New Post(0)