Validates the char is 0-9 or a dash - CSharp System

CSharp examples for System:Char

Description

Validates the char is 0-9 or a dash

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from w  ww. j  a va2 s  . co  m

public class Main{
        /// <summary>
		/// Validates the char is 0-9 or a dash
		/// </summary>
		public static bool IsSigned(this char c)
		{
			return char.IsDigit(c) || c == '-';
		}
        /// <summary>
		/// Validates all chars are 0-9, or a dash as the first value
		/// </summary>
		public static bool IsSigned(this string str)
		{
			if (string.IsNullOrWhiteSpace(str))
			{
				return false;
			}

			return str[0].IsSigned() && str.Substring(1).All(IsUnsigned);
		}
}

Related Tutorials