ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsMobileValid

For Philippine mobile code but can also be adjusted based on your mobile network code. Check if the given number is a valid formatted international number.

Source

using System.Text.RegularExpressions;

public static class MyExtension
{
	public static bool IsValidMobile(this string number)
	{
		bool bFound = false;
		try
		{
			bFound = Regex.IsMatch(number, @"\A\+\b(639)[012]{1}[0-9]{1}[0-9]{3}[0-9]{4}\b\Z");
		}
		catch (ArgumentException)
		{
			
		}

		return bFound;
	}
}

Example

Console.WriteLine("Valid Mobile: +639203782321:\t{0}", "+639303782321".IsValidMobile());

Author: Earljon Hidalgo

Submitted on: 10 apr. 2008

Language: C#

Type: System.Boolean

Views: 4944