Checks if the string contains numbers via Regex - CSharp System.Text.RegularExpressions

CSharp examples for System.Text.RegularExpressions:Match Number

Description

Checks if the string contains numbers via Regex

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;/*from  w  w  w  .  ja  v  a2  s  . c om*/

public class Main{
        //Checks if the string contains numbers
        //hello -> False
        //h3llo -> True
        public static bool HasNumbers(string input)
        {
            return Regex.IsMatch(input, "\\d+");
        }
}

Related Tutorials