Posta Kodu Doğrulama

RegularExpressionValidator kullanarak kullanıcının girmiş olduğu posta adresini istediğimiz ile ait olup olmadığı kontrol ettirebiliriz örnek olarak amasya 05100 ilçeleri ve ya köyleride 05120 05900 şeklinde gidiyor yani 05 ile başlaması lazım
onun için doğrulama kontrolümüze yazacağımız kural “^05\d{3}” şeklinde olacak
RegularExpressionValidator 2

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RegularExpressionValidator postakodu.aspx.cs" Inherits="aspnetornekleri.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">RegularExpressionValidator<br />Posta Kodu Doğrulama </h2>
<asp:Label ID="Label1" runat="server">
</asp:Label>
<br /><br />
<asp:Label ID="Label2" runat="server" Text="Posta Kodu...:" Font-Bold="true" ForeColor="SlateBlue" >
</asp:Label>
<asp:TextBox ID="TextBox1" runat="server" >
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Text="*" >
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="^05\d{3}" ControlToValidate="TextBox1" ErrorMessage="Amasyaya ait olmayan posta kodu"
></asp:RegularExpressionValidator>
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Amasya Posta Kodu Doğrula" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace aspnetornekleri
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!this.IsPostBack)
            {
                Label1.Font.Bold = true;
                Label1.Font.Italic = true;
                Label1.Font.Size = FontUnit.Large;
                Label1.ForeColor = System.Drawing.Color.Crimson;
                TextBox1.BackColor = System.Drawing.Color.SlateBlue;
                TextBox1.ForeColor = System.Drawing.Color.AliceBlue;
                Button1.Font.Bold = true;
                Button1.ForeColor = System.Drawing.Color.SlateBlue;
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = "Girilen Posta Kodu" + TextBox1.Text.ToString() +" ve Amasya iline ait.. ";
        }  
    }
}

You may also like...

Subscribe
Bildir
guest
0 Yorum
Inline Feedbacks
View all comments
0
Yazı hakkındaki yorum, görüş ve önerilerinizi yazınx
()
x