CSharp examples for System.Text.RegularExpressions:Match Number
Check whether is a valid money format by regex
using System.Text.RegularExpressions; using System.Text; using System.Data; using System;//w ww . j av a 2 s . c o m public class Main{ /// <summary> /// Check whether is a valid money format. /// </summary> /// <param name="sender"></param> /// <returns></returns> /// <see>http://regexlib.com/DisplayPatterns.aspx?categoryId=3&cattabindex=3</see> /// <remarks> /// <b>Author</b> yeang-shing.then<br/> /// <b>Since</b> 2009-04-29<br/> /// </remarks> public static bool IsMoney(string sender) { if (sender == null) return false; if (sender.Trim().Length == 0) return false; Regex regex = new Regex("^(\\d|-)?(\\d|,)*\\.?\\d*$");//"^[-+]?\\d*\\.?\\d*$"); return regex.IsMatch(sender); } }