Keşfet

JSF PrimeFaces Email Regex Kontrolu

Webci-Abi

Yeni Üye
Katılım
1 Nis 2021
Mesajlar
93
Tepkime puanı
0
Puanları
0
Yaş
29
PHP- Kodu:
Kod:
[LEFT][CODE][COLOR=#000000] [COLOR=#0000BB]  [/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]f[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]view[/COLOR][COLOR=#007700]>
 <[/COLOR][COLOR=#0000BB]h[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]form id[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"form"[/COLOR][COLOR=#007700]>   
 <[/COLOR][COLOR=#0000BB]p[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]growl id[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"growl" [/COLOR][COLOR=#0000BB]showDetail[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"true"  [/COLOR][COLOR=#0000BB]life[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"3000"[/COLOR][COLOR=#007700]/>
 <[/COLOR][COLOR=#0000BB]p[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]panel id[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"panel-----" [/COLOR][COLOR=#0000BB]header[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"-----nuzu Paylaşınız.." [/COLOR][COLOR=#0000BB]style[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"margin-bottom:10px;"[/COLOR][COLOR=#007700]> 
      <[/COLOR][COLOR=#0000BB]h[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]outputLabel [/COLOR][COLOR=#007700]for=[/COLOR][COLOR=#DD0000]"email" [/COLOR][COLOR=#0000BB]value[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"Email"  [/COLOR][COLOR=#007700]/>
    <[/COLOR][COLOR=#0000BB]p[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]inputText value[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"#{-----Control.-----.-----Email}" [/COLOR][COLOR=#0000BB]validatorMessage[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"Email formatını kontrol ediniz!" [/COLOR][COLOR=#0000BB]size[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"50"
     [/COLOR][COLOR=#0000BB]id[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"email" [/COLOR][COLOR=#0000BB]label[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"Email" [/COLOR][COLOR=#0000BB]required[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"true"[/COLOR][COLOR=#007700]>
     <[/COLOR][COLOR=#0000BB]f[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]validateRegex pattern[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" [/COLOR][COLOR=#007700]/>
     </[/COLOR][COLOR=#0000BB]p[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]inputText[/COLOR][COLOR=#007700]>
     <[/COLOR][COLOR=#0000BB]p[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]message [/COLOR][COLOR=#007700]for=[/COLOR][COLOR=#DD0000]"email" [/COLOR][COLOR=#007700]/>    
    </[/COLOR][COLOR=#0000BB]p[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]panel[/COLOR][COLOR=#007700]>
<[/COLOR][COLOR=#0000BB]p[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]commandButton value[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"Ekle" [/COLOR][COLOR=#0000BB]actionListener[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"#{-----Control.save()}" [/COLOR][COLOR=#0000BB]icon[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"ui-icon-disk" [/COLOR][COLOR=#0000BB]update[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"growl,panel-----" [/COLOR][COLOR=#007700]/>  
    </[/COLOR][COLOR=#0000BB]h[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]form[/COLOR][COLOR=#007700]>
    </[/COLOR][COLOR=#0000BB]f[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]view[/COLOR][COLOR=#007700]>  [/COLOR][/COLOR]
[/LEFT][/CODE]
</div>

Istemci taraflı email regex kontrolu inputText' imiz için,

PHP- Kodu:
Kod:
[LEFT][ICODE][COLOR=#000000] [COLOR=#007700]<[/COLOR][COLOR=#0000BB]f[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000BB]validateRegex pattern[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" [/COLOR][COLOR=#007700]/>  [/COLOR][/COLOR][/ICODE][/LEFT]



Regex'e uygum olmayan formatta ise vereceğimiz client mesaj için inputText'in validatorMessage özelliğini kullanıyoruz.

PHP- Kodu:
Kod:
[LEFT][ICODE][COLOR=#000000] [COLOR=#0000BB]validatorMessage[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"Email formatını kontrol ediniz!"  [/COLOR][/COLOR][/ICODE][/LEFT]



Bu kısım client taraflı kontroller idi.
Asıl önemli olan sunucu taraflı kontrollerimiz.
Validasyonumuz için bir JSF ManagedBan oluşturuyoruz fakat Validator interface sınıf'ımızı implements ediyoruz. implements ettiğimiz Validator sınıfımızın default constructor olan override validate metodu ile gelmektedir.

PHP- Kodu:
Kod:
[LEFT][CODE][COLOR=#000000] [COLOR=#0000BB]package Egas[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]View[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]ControllerBeans[/COLOR][COLOR=#007700];
[/COLOR]
[COLOR=#0000BB]import javax[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]faces[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]bean[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]ManagedBean[/COLOR][COLOR=#007700];[/COLOR]
[COLOR=#0000BB]import javax[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]faces[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]bean[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]RequestScoped[/COLOR][COLOR=#007700];[/COLOR]
[COLOR=#0000BB]import java[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]util[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]regex[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]Matcher[/COLOR][COLOR=#007700];[/COLOR]
[COLOR=#0000BB]import java[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]util[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]regex[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]Pattern[/COLOR][COLOR=#007700];[/COLOR]
[COLOR=#0000BB]import javax[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]faces[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]application[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]FacesMessage[/COLOR][COLOR=#007700];[/COLOR]
[COLOR=#0000BB]import javax[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]faces[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]component[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]UIComponent[/COLOR][COLOR=#007700];[/COLOR]
[COLOR=#0000BB]import javax[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]faces[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]context[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]FacesContext[/COLOR][COLOR=#007700];[/COLOR]
[COLOR=#0000BB]import javax[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]faces[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]validator[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]Validator[/COLOR][COLOR=#007700];[/COLOR]
[COLOR=#0000BB]import javax[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]faces[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]validator[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]ValidatorException[/COLOR][COLOR=#007700];

[/COLOR]
[COLOR=#FF8000]/**
 *
 * [MENTION=21475]AuthoR[/MENTION] turgay
 */[/COLOR]
[COLOR=#007700][[/COLOR][COLOR=#0000BB]MENTION[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]88634[/COLOR][COLOR=#007700]][/COLOR][COLOR=#0000BB]mana[/COLOR][COLOR=#007700][/[/COLOR][COLOR=#0000BB]MENTION[/COLOR][COLOR=#007700]][/COLOR][COLOR=#0000BB]gedBean[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]name [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"-----Validator"[/COLOR][COLOR=#007700])
[[/COLOR][COLOR=#0000BB]MENTION[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]22994[/COLOR][COLOR=#007700]][/COLOR][COLOR=#0000BB]RequeSt[/COLOR][COLOR=#007700][/[/COLOR][COLOR=#0000BB]MENTION[/COLOR][COLOR=#007700]][/COLOR][COLOR=#0000BB]Scoped[/COLOR]
[COLOR=#007700]public class -----[/COLOR][COLOR=#0000BB]Validator [/COLOR][COLOR=#007700]implements [/COLOR][COLOR=#0000BB]Validator[/COLOR][COLOR=#007700]{

    private static final [/COLOR][COLOR=#0000BB]String EMAIL_PATTERN [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"[\\w\\.-]*[a-zA-Z0-9_]@[\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]"[/COLOR][COLOR=#007700];
    private [/COLOR][COLOR=#0000BB]Pattern pattern[/COLOR][COLOR=#007700];
    private [/COLOR][COLOR=#0000BB]Matcher matcher[/COLOR][COLOR=#007700];

    [/COLOR][COLOR=#FF8000]/** Creates a new instance of -----Validator */
    [/COLOR][COLOR=#007700]public -----[/COLOR][COLOR=#0000BB]Validator[/COLOR][COLOR=#007700]() {        

    }    

 @[/COLOR][COLOR=#0000BB]Override
    [/COLOR][COLOR=#007700]public [/COLOR][COLOR=#0000BB]void validate[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]FacesContext context[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]UIComponent component[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]Object value[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000BB]throws ValidatorException [/COLOR][COLOR=#007700]{

        throw new [/COLOR][COLOR=#0000BB]UnsupportedOperationException[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Format henüz desteklenmiyor."[/COLOR][COLOR=#007700]);
    }

    public [/COLOR][COLOR=#0000BB]void validateEmail[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]FacesContext context[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]Object value[/COLOR][COLOR=#007700]) {
        [/COLOR][COLOR=#0000BB]pattern [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]Pattern[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]compile[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]EMAIL_PATTERN[/COLOR][COLOR=#007700]);
        [/COLOR][COLOR=#0000BB]matcher [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]pattern[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]matcher[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]value[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]toString[/COLOR][COLOR=#007700]());
        if (![/COLOR][COLOR=#0000BB]matcher[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]matches[/COLOR][COLOR=#007700]()) {
            [/COLOR][COLOR=#0000BB]FacesMessage msg [/COLOR][COLOR=#007700]=
                    new [/COLOR][COLOR=#0000BB]FacesMessage[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Email adres hatası."[/COLOR][COLOR=#007700],
                    [/COLOR][COLOR=#DD0000]"Geçersiz Email formatı."[/COLOR][COLOR=#007700]);
            [/COLOR][COLOR=#0000BB]msg[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]setSeverity[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]FacesMessage[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]SEVERITY_ERROR[/COLOR][COLOR=#007700]);
            [/COLOR][COLOR=#0000BB]System[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]out[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]println[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]msg[/COLOR][COLOR=#007700]);
            throw new [/COLOR][COLOR=#0000BB]ValidatorException[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]msg[/COLOR][COLOR=#007700]);

        }
        throw new [/COLOR][COLOR=#0000BB]UnsupportedOperationException[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Format henüz desteklenmiyor."[/COLOR][COLOR=#007700]);
    }

}  [/COLOR][/COLOR]
[/LEFT][/CODE]
 
Güzel bilgiler için teşekkürler
 

Konu görüntüleyen kullanıcılar

Benzer konular

Geri
Üst