Created
February 20, 2014 03:36
-
-
Save Fhernd/9106685 to your computer and use it in GitHub Desktop.
Clase estática utilitaria en C#.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Text.RegularExpressions; | |
| namespace Recetas.Ch01 | |
| { | |
| ///<summary> | |
| /// Conjunto de utilidades para la validación de recursos Web: URL, email. | |
| ///</summary> | |
| public static class UtilitarioWeb | |
| { | |
| ///<summary> | |
| /// Valida una dirección de email: id@dominio | |
| ///</summary> | |
| /// <param name="email">Dirección de email a validar.</param> | |
| ///<returns> | |
| /// true si la dirección de correo electrónico es válida, false en caso contrario. | |
| ///</returns> | |
| public static bool ValidarEmail(string email) | |
| { | |
| Regex regex = new Regex(@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\." + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$"); | |
| return regex.IsMatch(email); | |
| } | |
| ///<summary> | |
| /// Valida una dirección Web. | |
| ///</summary> | |
| /// <param name="url">URL a validar.</param> | |
| /// <returns> | |
| /// true si la dirección es valida, y false si no lo es. | |
| ///</returns> | |
| public static bool ValidarUrl(string url) | |
| { | |
| string pattern = @"^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$"; | |
| Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); | |
| return reg.IsMatch(url); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment