Checks whether the string starts with a number or not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebOssApplications.Common
{
public static class Extensions
{
/// <summary>
/// Checks whether the string starts with a number or not
/// </summary>
/// <param name="value">Value to check</param>
/// <returns>True if the string starts with a number</returns>
/// <exception cref="ArgumentNullException">Throws if value is null</exception>
/// <exception cref="ArgumentOutOfRangeException">Throws if value is empty</exception>
public static bool StartsWithNumber(this string value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
if (string.IsNullOrEmpty(value))
{
throw new ArgumentOutOfRangeException("value");
}
return char.IsDigit(value, 0);
}
}
}
Related examples in the same category