Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if there is phone number in string C#

Tags:

string

c#

regex

I read a string that includes all types of characters. I want to check whether there is in the string, consisting of sub-string at least 7 digits. What is the best way to do it?

like image 846
Mosh Feu Avatar asked Feb 03 '26 12:02

Mosh Feu


2 Answers

use a regular expression

[0-9]{7,}

bool includesPhone = Regex.IsMatch("phone number 123456789", "[0-9]{7,}");
like image 164
juergen d Avatar answered Feb 05 '26 02:02

juergen d


Use Regex - something like \d{7,}

like image 40
manojlds Avatar answered Feb 05 '26 01:02

manojlds