Regular Expression (Regex) for toll free number 1 800 ###-####

Last Reply one year ago By Shashikant

Posted one year ago

What is the regular expression for USA toll free number 1 800 ###-####? How to validate this for phone using c#? i want the regular expression only

Posted one year ago

Please refer below code.

C#

if (System.Text.RegularExpressions.Regex.IsMatch(txtNumber.Text.Trim(), @"^1[\s]?(800)?[\s\-]?\d{3}\-?\d{4}$"))
{
    // this will be valid if phone is 1 800 333-4453
    // this will be valid if phone is 1 800333-4453
    // this will be valid if phone is 1800333-4453
    // this will be valid if phone is 18003334453
    // If you want mandatory space and hyphen in number then use below regex
    // "^1[\s]?(800)[\s]\d{3}\-\d{4}$"
}

VB

If System.Text.RegularExpressions.Regex.IsMatch(txtNumber.Text.Trim(), "^1[\s]?(800)?[\s\-]?\d{3}\-?\d{4}$") Then
         ' this will be valid if phone is 1 800 333-4453
         ' this will be valid if phone is 1 800333-4453
         ' this will be valid if phone is 1800333-4453
	 ' this will be valid if phone is 18003334453
	 ' If you want mandatory space and hyphen in number then use below regex
	 ' "^1[\s]?(800)[\s]\d{3}\-\d{4}$"
End If

I hope this will help you out.

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html