/// <summary> /// Fonction qui va tester le code postal /// </summary> /// Le code postal A tester /// <returns>True si le code postal est correct, False sinon</returns> public static bool f_Verifie_CP(string Code_Postal) { //Par défaut on retourne true bool retour = true; try { //ON fait les tests qu'il faut if( (Convert.ToInt32(Code_Postal)<1000) || (Convert.ToInt32(Code_Postal)> 99999) ) { retour = false; } } catch(Exception xcp) { MessageBox.Show(xcp.Message); } return retour; }
namespace Outils { public class Fonction { /// <summary> /// Fonction qui va tester le code postal /// </summary> /// Le code postal A tester /// <returns>True si le code postal est correct, False sinon</returns> public static bool f_Verifie_CP(string Code_Postal) { //Par défaut on retourne true bool retour = true; //ON fait les tests qu'il faut if( (Code_Postal<"01000") || (Code_Postal> "99999") ) { retour = false; } return retour; } } }
if(Outils.Fonction.f_Verifie_CP(_Organisme.codePostal)) { //...... }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionusing System.Text.RegularExpressions; void MatchRegex(string input ) { RegexOptions options = RegexOptions.None; Regex regex = new Regex(@"^\d{5}$", options); bool isMatch = regex.IsMatch(input); if( isMatch ) return true return false; }