Jonga idilesi ye-imeyile ngeJavaScript kunye neeNtetho eziQhelekileyo

Kwixesha elidlulileyo ndibeke Amandla okuKhangela okuKhangela usebenzisa iJavaScript kunye neeNkcazo eziQhelekileyo. Kwakwelo nqaku linye, unokujonga ukwakheka kwedilesi ye-imeyile usebenzisa indlela efanayo yokubonisa (regex).

Ukuba into yakho yefom inayo id = "idilesi ye-imeyile" kwaye wongeza ifom onSubmit = ”buyela itshekhi ye-imeyile ();", Lo ngumsebenzi weJavascript onokuwusebenzisa ukubuyisela isilumkiso ukuba idilesi ye-imeyile inesakhiwo esifanelekileyo okanye hayi:

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;
}
}

Umsebenzi uqinisekisa imixholo ye-imeyile kuleyo yecebo lokucoca ulwelo. Ukuba uthelekiso aluphumeleli, lukhupha isilumkiso kwaye lubuyisele ukugxila kumhlaba wedilesi ye-imeyile!

41 Comments

  1. 1

    Kwiifomu ezineedilesi ze-imeyile ezininzi, kuya kuba kuhle ukwenza iklasi="idilesi ye-imeyile". Ukuba unethala leencwadi leprototype.js (http://www.prototypejs.org) ibandakanyiwe kwiphepha ungenza into enje:

    var valid = yinyani;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    $$('.emailaddress').nganye( umsebenzi(imeyile) {
    ukuba (!hluza.test(imeyile.value)) {
    isilumkiso(?Nceda unikeze idilesi ye-imeyile esebenzayo?);
    imeyile.ujoliso;
    esebenzayo = bubuxoki;
    }
    });
    imbuyekezo iyasebenza;

  2. 5
  3. 7

    Ndiyawuthanda lo mbono, kodwa ndingathandabuza ukwamkela le ntetho yarhoqo ngaphandle kwenkcazelo yokuba zeziphi iidilesi ze-imeyile ezisemthethweni ezingazamkeliyo kwaye zeziphi iidilesi ezingekho mthethweni ezizivumelayo.

    Umzekelo wentetho eqhelekileyo eyenza umsebenzi ondilisekileyo ecaleni kwengcaciso engaguqukiyo, bona oku:

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

    Ukhetho lwam lobuqu kukugubungela uninzi lwamatyala alula kwaye ndikhuphe isilumkiso sayo yonke enye into kunokuba ndiyale. Ukuba uBob ufuna ngokwenene ukuhambisa bob@com.museum ngaphandle kwe bob@museum.com, kutheni ungamvumeli?

    • 8

      Molo Reg,

      Unokuvavanya iRegex usebenzisa i Umvavanyi weRegex kwi-Intanethi.

      Kwakhona, ngokuqinisekileyo kuninzi okunokwenziwa ukuba ufuna ukuqinisekisa i idilesi yemeyile isebenza ngokungqinelana ne-RFC.

      Kukho izizathu ezimbalwa zokungavumeli umntu ukuba angenise idilesi ye-imeyile engasebenziyo:
      1. Baza kucaphuka kuwe xa i-imeyile abebeyilindele ingangeni – nokuba ibilityala lakho okanye ibiyimpazamo yakho idilesi ifakwe ngokungachanekanga.
      2. Ukuba i-com.museum ibiyindawo esebenzayo kwaye, masithi, Yahoo! isebenzile - nayiphi na idilesi ye-imeyile ethe yagqabhuka inokuba nefuthe elibi kudumo lwenkampani yakho lokuhanjiswa kwe-imeyile. Oku kunokukhokelela ekubeni yonke i-imeyile yenkampani yakho ivalwe.
      3. Ukuba umboneleli wakho wesevisi ye-imeyile ukuvumela ukuba ungene bob@com.museum, uya kuhlawula kwakhona i-imeyile nganye ethunyelwe kuloo dilesi ye-imeyile de bayikhuphile loo dilesi ngenxa yokubhampa. Ndingasuka kuyo nayiphi na i-ESP enokuvumela idilesi ye-imeyile engasebenziyo ngolo hlobo - bathatha nje imali yakho!

      Enkosi ngokuma!
      Doug

  4. 9
  5. 10

    Kukho indlela elula kakhulu yokubhala intetho:
    var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
    – Ngesilungisi sokugqibela /i akukho mfuneko yokubonisa uluhlu lweemeko eziphezulu.
    Andazi nanye TLD enamanani kuyo.
    Kwinqaku elisecaleni, ndivumela i-TLD ukuya kuthi ga kwi-6 chars; abatsha bafika rhoqo kwaye awusoze wazi (kakuhle, ezinye zexesha elizayo zinokuba namanani kuyo, ndiyazi).

  6. 11

    Molo apho,

    Ndizama ukusebenzisa oku kwifomu esele ikhona ngexesha lokwenyani, kodwa oku akubonakali ngathi kungqinisiswa ngexesha lokwenyani njengomkhangeli wamandla wephasiwedi...

    Okanye, ngaba andinalwazi, kwaye ayisebenzi kum?

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

    Ulungiso nje oluncinci: Intetho eqhelekileyo inokongeza ()+ ekugqibeleni. Kufuneka ifundeke:

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

    Ngeyokuqala naziphi na ubude be-TLDs ziyakwamkelwa (ezingaphosakalanga ngokusuka entliziyweni njengoko abanye beye bachaza, kodwa ukuba yayiyinjongo le ntetho inokufinyezwa).

  11. 18

    Ngaba unganceda uchaze inkcazo eqhelekileyo yale khowudi kunye nendlela esebenza ngayo? Kwakhona malunga .test – Ngaba .test ingxelo engagqibekanga kwijavascript ukujonga izinto ozenzileyo kwikhowudi engentla?

  12. 19

    Le yikhowudi emfutshane yokubonakalisa i-imeyile-

    umsebenzi qinisekisa iEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    buyisela i-imeyilePattern.test(id);

    }
    Deepak Rai
    varanasi

  13. 20

    Le yikhowudi emfutshane yokubonakalisa i-imeyile-

    umsebenzi qinisekisa iEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    buyisela i-imeyilePattern.test(id);

    }
    Deepak Rai
    varanasi

  14. 21
  15. 22
  16. 23

    Enkosi, kodwa kukho impazamo kule regex. Andiyongcali ye-regex, kodwa ndizamile i-imeyile:

    test@test

    kwaye yadlula i-regex… Ndaqaphela ukuba iyasilela ukubaleka "." ngoko kufuneka:

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

  17. 24
  18. 27

    Ewe, oku kujongwa nje ngokurhabaxa kodwa hayi 100% ichanekile, umzekelo oku kuyakulunga john_doe.@gmail.com eneneni engeyiyo idilesi ye-imeyile esebenzayo (ichaphaza alivumelekanga njengonobumba wokugqibela kwindawo yendawo ye-imeyile).
    Kwakhona yayiya kwamkela john...doe@gmail.com engasebenziyo kwakhona kuba ingenakuba ngaphezulu kwechaphaza elinye kulandelelwano.

    Ezi zezinye nje iziphene endiziqapheleyo ekuqaleni.
    Injongo yam ayikuko ukuhlamba nje oku xa kukho umntu oceba ukusebenzisa oku njengetshekhi yokhuseleko - engakhuselekanga ngokwaneleyo.

    Ngolwazi malunga needilesi ze-imeyile ezisebenzayo jonga oku: http://en.wikipedia.org/wiki/E-mail_address

  19. 28

    Deepak,

    Ngokwenyani, ndicinga ukuba kufuneka ufake isicelo sokubalekela ichaphaza (“.”). Ke, umsebenzi wakho kufuneka ube, endaweni yoko:

    umsebenzi qinisekisa iEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    buyisela i-imeyilePattern.test(id);

    }

    Ngaphandle koko, ichaphaza liza kuthetha "nawuphi na umlinganiswa". Ndiyakholelwa ukuba abalinganiswa abakhethekileyo kufuneka babaleke.

    mbuliso,

    Federico

  20. 29

    umsebenzi qinisekisa iEmail(fld) {
    var error="";
    var tfld = trim(fld.value); // ixabiso lebala elinendawo emhlophe esikiweyo
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

    ukuba (fld.value == "Faka idilesi ye-imeyile yakho") {

    impazamo = "Nceda ufake idilesi ye-imeyile yakho.n";
    } okunye ukuba (!emailFilter.test(tfld)) {//test email yamagama angekho mthethweni

    impazamo = "Nceda ufake idilesi ye-imeyile esebenzayo.n";
    } okunye ukuba (fld.value.match(illegalChars)) {

    impazamo = "Nceda ufake idilesi ye-imeyile esebenzayo.n";
    }
    imposiso yokubuyisela;
    }

  21. 30

    umsebenzi qinisekisa iEmail(fld) {
    var error="";
    var tfld = trim(fld.value); // ixabiso lebala elinendawo emhlophe esikiweyo
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

    ukuba (fld.value == "Faka idilesi ye-imeyile yakho") {

    impazamo = "Nceda ufake idilesi ye-imeyile yakho.n";
    } okunye ukuba (!emailFilter.test(tfld)) {//test email yamagama angekho mthethweni

    impazamo = "Nceda ufake idilesi ye-imeyile esebenzayo.n";
    } okunye ukuba (fld.value.match(illegalChars)) {

    impazamo = "Nceda ufake idilesi ye-imeyile esebenzayo.n";
    }
    imposiso yokubuyisela;
    }

  22. 31

    umsebenzi qinisekisa iEmail(fld) {
    var error="";
    var tfld = trim(fld.value); // ixabiso lebala elinendawo emhlophe esikiweyo
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

    ukuba (fld.value == "Faka idilesi ye-imeyile yakho") {

    impazamo = "Nceda ufake idilesi ye-imeyile yakho.n";
    } okunye ukuba (!emailFilter.test(tfld)) {//test email yamagama angekho mthethweni

    impazamo = "Nceda ufake idilesi ye-imeyile esebenzayo.n";
    } okunye ukuba (fld.value.match(illegalChars)) {

    impazamo = "Nceda ufake idilesi ye-imeyile esebenzayo.n";
    }
    imposiso yokubuyisela;
    }

  23. 32

    umsebenzi qinisekisa iEmail(fld) {
    var error="";
    var tfld = trim(fld.value); // ixabiso lebala elinendawo emhlophe esikiweyo
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

    ukuba (fld.value == "Faka idilesi ye-imeyile yakho") {

    impazamo = "Nceda ufake idilesi ye-imeyile yakho.n";
    } okunye ukuba (!emailFilter.test(tfld)) {//test email yamagama angekho mthethweni

    impazamo = "Nceda ufake idilesi ye-imeyile esebenzayo.n";
    } okunye ukuba (fld.value.match(illegalChars)) {

    impazamo = "Nceda ufake idilesi ye-imeyile esebenzayo.n";
    }
    imposiso yokubuyisela;
    }

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

Ingaba ucinga ntoni?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda indlela idatha yakho yokubhaliweyo isetyenziswe ngayo.