Tarisa Email Kero neJavaScript uye Yakajairika Matauriro

Nguva pfupi yapfuura ndakaisa a Pasiwedhi Simba Rekutarisa uchishandisa JavaScript uye Zvakajairika Mataurirwo. Patsamba imwechete iyoyo, unogona zvakare kutarisa chimiro cheiyo kero yeemail uchishandisa imwecheteyo expression expression (regex) nzira.

Kana chimiro chako chine fomu id = "emailadress" uye iwe unowedzera fomu onSubmit = ”dzoka checkEmail ();", Iri ibasa reJavascript raunogona kushandisa kudzosa yambiro kana email kero ine chimiro chakakodzera kana kwete:

function checkEmail() {
var email = document.getElementById('emailaddress');
var filter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
email.focus;
return false;
}
}

Basa racho rinogonesa zvirimo mukati meiyo email kune izvo zvesefa. Kana iyo fananidzo ikakundikana, inobuda yambiro uye inodzorera tarisiro kumashure kune iyo email kero munda!

41 Comments

  1. 1

    Kune mafomu ane akawanda email kero, zvingave zvakanaka kuita kirasi = "emailaddress". Kana iwe uine prototype.js raibhurari (http://www.prototypejs.org) inosanganisirwa pane peji iwe unogona kuita seizvi:

    var valid = chokwadi;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    $$('.emailaddress'). chimwe nechimwe( basa(email) {
    kana (!filter.test(email.value)) {
    chenjedzo(?Ndokumbirawo mupe email kero inoshanda?);
    email.focus;
    kushanda = nhema;
    }
    });
    return valid;

  2. 5
  3. 7

    Ini ndinoda zano, asi ndingazeza kutora iyi yakajairika kutaura pasina tsananguro yekuti ndeapi maero e-email emutemo aasingabvume uye kuti ndeapi kero dzisiri pamutemo dzaanobvumidza.

    Kuti uwane muenzaniso wekutaura kwechinyakare kunoita basa rakanaka padivi petsananguro yekuti inyaya dzipi dzaasingavhare, ona izvi:

    http://www.regular-expressions.info/email.html

    Zvandinoda ndezvokuvhara mazhinji emakesi akareruka uye kupa yambiro kune zvimwe zvese pane kuzviramba. Kana Bob achida chaizvo kuzviisa pasi bob@com.museum pane ku bob@museum.com, wadii kumurega?

    • 8

      Hi Reg,

      Unogona kuyedza iyo Regex uchishandisa a Online Regex Tester.

      Zvakare, pane zvimwe zvakawanda zvinogona kuitwa kana iwe uchida kuve nechokwadi che chikero chetsamba yemumhepo inoshanda zvinoenderana neRFC.

      Pane zvikonzero zvishoma zvekusatendera mumwe munhu kuisa email kero isiriyo:
      1. Vanozosvotwa newe kana email yavaitarisira ikasapinda - zvisinei nekuti yaive mhosva yako here kana kuti kwete kero yaiswa zvisizvo.
      2. Kana com.museum yaive domain inoshanda uye, ngatiti, Yahoo! yakashanda nayo - chero email kero yakabhoweka inogona kukanganisa mukurumbira wekambani yako wekutumira email. Izvi zvinogona kuita kuti email yekambani yako yese ivharwe.
      3. Kana email sevhisi yako yakakubvumidza kuti upinde bob@com.museum, iwe unobhadharawo email yega yega inotumirwa kune iyo email kero kusvika vabvisa iyo kero nekuda kwekubhomba. Ini ndaizosiya chero ESP yaizobvumidza email kero isiriyo seizvi - ivo vari kungotora mari yako!

      Kutenda nekumira!
      Doug

  4. 9
  5. 10

    Pane nzira iri nyore yekunyora chirevo:
    var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
    -Neyekupedzisira modifier /i hapana chikonzero chekuratidza iyo yepamusoro kesi renji.
    – Hapana chandinoziva TLD ine manhamba mairi.
    Pamusoro pechinyorwa, ini ndinobvumira TLD kusvika ku6 chars; zvitsva zvinosvika nguva nenguva uye haumboziva (zvakanaka, mamwe emangwana anogona kunge aine manhamba mairi, ndinoziva).

  6. 11

    Mhoroi apo,

    Ndiri kuedza kushandisa izvi muchimiro chiripo munguva-chaiyo, asi izvi hazviratidzike kuva zvinosimbisa munguva chaiyo senge password yako yekuongorora simba...

    Kana kuti, inini handizivi, uye hazvisi kushanda kwandiri?

  7. 12
  8. 13
  9. 16
  10. 17

    Kungogadzirisa kudiki: Chirevo chenguva dzose chine chekuwedzera ()+ kumagumo. Inofanira kuverenga:

    ^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$

    Neyokutanga chero kureba kweTLD kwaizogamuchirwa (izvo zvisina kushata sezvakataurwa nevamwe, asi kana chiri icho chinangwa kutaura kwaigona kupfupikiswa).

  11. 18

    Ndokumbirawo mutsanangure mataurirwo anoitwa kodhi iyi uye kuti inoshanda sei? Zvakare nezve .test – Is .test a default statement in javascript to check things like you did in the code above?

  12. 19

    Iyi ipfupi kodhi yeemail kutaura-

    basa simbisaEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    dzorera emailPattern.test(id);

    }
    Deepak Rai
    varanasi

  13. 20

    Iyi ipfupi kodhi yeemail kutaura-

    basa simbisaEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    dzorera emailPattern.test(id);

    }
    Deepak Rai
    varanasi

  14. 21
  15. 22
  16. 23

    Ndatenda, asi pane kukanganisa mune ino regex. Ini handisi regex nyanzvi, asi ndakaedza email:

    test@test

    uye yakapfuura regex… Ndakaona iri kushaya kutiza "." saka zvinofanira kuva:

    /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/

  17. 24
  18. 27

    Zvakanaka, ichi chingori cheki cheki asi kwete 100% chakarurama, semuenzaniso izvi zvingave zvakanaka nazvo john_doe.@gmail.com iyo isiri iyo kero ye-e-mail chaiyo (doti haribvumidzwe semutambi wekupedzisira muchikamu chenzvimbo ye-e-mail).
    Zvakare zvaizobvuma john…doe@gmail.com iro harina basa zvakare sezvo kusingagone kuva rinopfuura doti rimwe mukutevedzana.

    Aya angori mamwe zvikanganiso zvandakaona pekutanga kuona.
    Chinangwa changu hachisi kugeza kungonongedza izvi kana mumwe munhu ari kuronga kushandisa izvi secheki yekuchengetedza - isina kuchengetedzeka zvakakwana.

    Kuti uwane ruzivo nezve e-mail kero inoshanda tarisa izvi: http://en.wikipedia.org/wiki/E-mail_address

  19. 28

    Deepak,

    Chaizvoizvo, ndinofunga iwe unofanirwa kunyorera kutiza iyo dot ("."). Saka, basa rako rinofanira kuva, pachinzvimbo:

    basa simbisaEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    dzorera emailPattern.test(id);

    }

    Zvikasadaro, doti raizoreva "chero hunhu". Ndinotenda kuti mavara akakosha akadai anoda kupukunyuka.

    maererano

    Federico

  20. 29

    basa simbisaEmail(fld) {
    var kukanganisa=””;
    var tfld = trim(fld.value); // kukosha kwemunda ine whitespace yakatemwa
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

    kana (fld.value == "Isa email yako Kero") {

    kukanganisa = "Ndapota isa Email yako kero.n";
    } zvimwe kana (!emailFilter.test(tfld)) {//test email yemavara asiri pamutemo

    kukanganisa = "Ndapota isa email kero inoshanda.n";
    } zvimwe kana (fld.value.match(illegalChars)) {

    kukanganisa = "Ndapota isa email kero inoshanda.n";
    }
    return error;
    }

  21. 30

    basa simbisaEmail(fld) {
    var kukanganisa=””;
    var tfld = trim(fld.value); // kukosha kwemunda ine whitespace yakatemwa
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

    kana (fld.value == "Isa email yako Kero") {

    kukanganisa = "Ndapota isa Email yako kero.n";
    } zvimwe kana (!emailFilter.test(tfld)) {//test email yemavara asiri pamutemo

    kukanganisa = "Ndapota isa email kero inoshanda.n";
    } zvimwe kana (fld.value.match(illegalChars)) {

    kukanganisa = "Ndapota isa email kero inoshanda.n";
    }
    return error;
    }

  22. 31

    basa simbisaEmail(fld) {
    var kukanganisa=””;
    var tfld = trim(fld.value); // kukosha kwemunda ine whitespace yakatemwa
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

    kana (fld.value == "Isa email yako Kero") {

    kukanganisa = "Ndapota isa Email yako kero.n";
    } zvimwe kana (!emailFilter.test(tfld)) {//test email yemavara asiri pamutemo

    kukanganisa = "Ndapota isa email kero inoshanda.n";
    } zvimwe kana (fld.value.match(illegalChars)) {

    kukanganisa = "Ndapota isa email kero inoshanda.n";
    }
    return error;
    }

  23. 32

    basa simbisaEmail(fld) {
    var kukanganisa=””;
    var tfld = trim(fld.value); // kukosha kwemunda ine whitespace yakatemwa
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

    kana (fld.value == "Isa email yako Kero") {

    kukanganisa = "Ndapota isa Email yako kero.n";
    } zvimwe kana (!emailFilter.test(tfld)) {//test email yemavara asiri pamutemo

    kukanganisa = "Ndapota isa email kero inoshanda.n";
    } zvimwe kana (fld.value.match(illegalChars)) {

    kukanganisa = "Ndapota isa email kero inoshanda.n";
    }
    return error;
    }

  24. 33
  25. 34
  26. 35
  27. 36
  28. 37
  29. 38
  30. 39
  31. 40

Unofungei?

Nzvimbo iyi inoshandisa Akismet kuderedza spam. Dzidza kuti sei deta yako inoshandiswa.