c sharp regular code to determine whether a number has a comma in its format

  • 2020-05-05 11:48:01
  • OfStack

  public   string   check_number(string   num_str)
                {

                        num_str   =   num_str.Trim();

                        if   (Regex.IsMatch(num_str,   @"^\d+(\.\d+)?$|^\d+(\,\d+)+(\.\d+)?$"))
                        {
                                this.Nonum   =   true;
                                return   num_str.Replace(",",   "");
                        }
                        else
                        {
                                this.Nonum   =   false;
                                return   num_str;

                        }

               
                }

eg:1.00
123,123
456,123.00  

Related articles: