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

    Kwiifom ezineedilesi ezininzi ze-imeyile, kungakuhle ukwenza iklasi = "i-imeyile". Ukuba uneprototype.js library (http://www.prototypejs.orgIfakiwe kwiphepha ungenza into enje:

    var esebenzayo = yinyani;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    $$ ('. emailaddress') nganye (umsebenzi (imeyile) {
    ukuba (! filter.test (imeyile.value)) {
    Isilumkiso (? Nceda unikeze idilesi ye-imeyile efanelekileyo?
    imeyile.focus;
    isebenze = bubuxoki;
    }
    });
    ukubuya kusebenza;

  2. 5
  3. 7

    Ndiyayithanda imbono, kodwa ndingathandabuza ukuyamkela le ntetho rhoqo ngaphandle kwenkcazo yokuba yeyiphi idilesi ye-imeyile engamkeliyo kwaye zeziphi iidilesi ezingekho mthethweni eziyivumelayo.

    Umzekelo wentetho eqhelekileyo eyenza umsebenzi onesidima kunye nengcaciso yokuba zeziphi iimeko ezingagubungeliyo, bona oku:

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

    Into endiyithandayo kukugubungela uninzi lwamatyala alula kwaye ndikhuphe isilumkiso sayo yonke into kunokuyala. Ukuba uBob ufuna ngenene ukungenisa bob@com.museum ngaphandle kwe bob@museum.com, kutheni engamvumeli?

    • 8

      Molo Reg,

      Ungayivavanya i-Regex usebenzisa ifayile ye- Uvavanyo lweRegex olukwi-Intanethi.

      Kwakhona, ngokuqinisekileyo kuninzi okunokwenziwa ukuba ufuna ukuqinisekisa ifayile ye- idilesi yemeyile isebenza ngokusesikweni kwi-RFC.

      Kukho izizathu ezimbalwa zokungavumeli umntu ukuba angene kwidilesi ye-imeyile engasebenziyo:
      1. Bayakucaphukisa xa i-imeyile ebebelindele ukuba ingafikeleli kuyo - nokuba ibiyimpazamo yakho idilesi ibifakwe ngokungachanekanga.
      2. Ukuba com.museum yayiyindawo efanelekileyo kwaye, masithi, Yahoo! Uyisebenzisile-nayiphi na idilesi ye-imeyile ethe yabhabha iya kuba nefuthe elibi kwinkampani yakho ekuzisweni kwe-imeyile. Oku kungakhokelela ekubeni yonke i-imeyile yenkampani yakho ivalwe.
      3. Ukuba umboneleli wakho we-imeyile ukuvumele ukuba ungene bob@com.museum, uya kuhlawula i-imeyile nganye ethunyelwe kuloo dilesi ye-imeyile bade babhalise kuloo dilesi ngenxa yokubheja. Ndingathanda ukucima nayiphi na i-ESP enokuvumela idilesi ye-imeyile engavumelekanga ngoluhlobo-bathatha imali yakho nje!

      Enkosi ngokuma!
      Doug

  4. 9
  5. 10

    Kukho indlela elula yokubhala intetho:
    var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
    -Kunye nesiguquli sokugqibela / i akukho sidingo sokubonisa uluhlu lwamacala aphezulu.
    - Andazi namnye TLD ngamanani kuyo.
    Kwinqaku elisecaleni, ndiyayivumela i-TLD ukuya kuthi ga kwi-6 chars; ezitsha zifika rhoqo kwaye awusoze wazi (ewe, ezinye zexesha elizayo zinokuba neenombolo kuyo, ndiyazi).

  6. 11

    Molo apho,

    Ndizama ukusebenzisa le ndlela esele ikho ngexesha lokwenyani, kodwa oku akubonakali ngathi kungasebenza ngexesha lokwenyani njengesiqinisekiso sokuqina kwephasiwedi yakho…

    Okanye, ngaba andinanto nje, kwaye iyasebenza kum?

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

    Ukulungiswa okuncinci: intetho eqhelekileyo ine-extra () + ekugqibeleni. Kufuneka ifundwe:

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

    Ngowokuqala nabuphi na ubude be-TLDs ziya kwamkelwa (ezingaphosakalanga ngokungathandabuzekiyo njengoko abanye bebonisile, kodwa ukuba yayiyinjongo le ntetho ingafinyezwa).

  11. 18

    Ngaba unganceda uchaze intetho eqhelekileyo yale khowudi kunye nendlela esebenza ngayo? Kananjalo malunga novavanyo .- Ngaba kuvavanya ingxelo engagqibekanga kwiJavaScript ukukhangela izinto njengoko uzenzile kule khowudi ingentla?

  12. 19

    Le khowudi imfutshane yokubonisa i-imeyile-

    Umsebenzi uqinisekisa i-imeyile (id)
    {
    var i-imeyilePattern = / ^ [a-zA-Z0-9._-)+@[a-zA-Z0-9.-)++
    buyisela i-imeyilePattern.test (id);

    }
    UDeakak Rai
    varanasi

  13. 20

    Le khowudi imfutshane yokubonisa i-imeyile-

    Umsebenzi uqinisekisa i-imeyile (id)
    {
    var i-imeyilePattern = / ^ [a-zA-Z0-9._-)+@[a-zA-Z0-9.-)++
    buyisela i-imeyilePattern.test (id);

    }
    UDeakak Rai
    varanasi

  14. 21
  15. 22
  16. 23

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

    vavanyo @ vavanyo

    kwaye yadlula kwi-regex… Ndiqaphele ukuba iyasinda ekubalekeni "." kufanelekile ukuba:

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

  17. 24
  18. 27

    Ewe, oku kukutshekishwa nje kodwa hayi i-100% ngokuchanekileyo, umzekelo oku kuya kulunga @ gmail.com leyo engeyiyo idilesi ye-imeyile esebenzayo (ichaphaza alivumelekanga njengophawu lokugqibela kwinxalenye yendawo ye-imeyile).
    Kananjalo iyakwamkela john ......doe@gmail.com engasebenziyo kuba ayinakubakho ichaphaza elingaphezulu kwesinye ngokulandelelana.

    Ezi zezinye zeziphene endizibonileyo ekuboneni kokuqala.
    Injongo yam ayikokubethisa nje ukubonisa oku xa umntu ecwangcisa ukusebenzisa oku njengokujonga ukhuseleko- engakhuselekanga ngokwaneleyo.

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

  19. 28

    Deepak,

    Ngokwenyani, ndicinga ukuba kufuneka ufake isicelo sokubaleka ichaphaza ("."). Ke, umsebenzi wakho kufanele ukuba, endaweni yoko:

    Umsebenzi uqinisekisa i-imeyile (id)
    {
    var i-imeyilePattern = / ^ [a-zA-Z0-9._-)+@[a-zA-Z0-9.-)++
    buyisela i-imeyilePattern.test (id);

    }

    Ngaphandle koko, ichaphaza liya kuthetha "nawuphi na umlinganiswa". Ndiyakholelwa ukuba abalinganiswa abanjalo bafuna ukubaleka.

    mbuliso,

    Federico

  20. 29

    Umsebenzi uqinisekisa i-imeyile (fld) {
    var impazamo = "";
    I-var tfld = i-trim (ixabiso le-fld); // Ixabiso lendawo enendawo emhlophe ecinyiweyo
    var emailFilter = / ^ [^@ ]+@@ ^^@. ]+. [^@ ]*ww$/;
    var engekho mthethweniChars = / [(),;: \ ”[]] /;

    ukuba (fld.value == "Ngenisa idilesi yemeyile yakho") {

    Impazamo = "Nceda ufake idilesi ye-imeyile.n";
    } Enye into ukuba (! imeyileFilter.test (tfld)) {// vavanya i-imeyile ngoonobumba abangavumelekanga

    Impazamo = "Nceda ngenisa idilesi ye-imeyile eyiyo.n";
    } Enye into ukuba (fld.value.match (iChars engekho mthethweni)) {

    Impazamo = "Nceda ngenisa idilesi ye-imeyile eyiyo.n";
    }
    buyisela impazamo;
    }

  21. 30

    Umsebenzi uqinisekisa i-imeyile (fld) {
    var impazamo = "";
    I-var tfld = i-trim (ixabiso le-fld); // Ixabiso lendawo enendawo emhlophe ecinyiweyo
    var emailFilter = / ^ [^@ ]+@@ ^^@. ]+. [^@ ]*ww$/;
    var engekho mthethweniChars = / [(),;: \ ”[]] /;

    ukuba (fld.value == "Ngenisa idilesi yemeyile yakho") {

    Impazamo = "Nceda ufake idilesi ye-imeyile.n";
    } Enye into ukuba (! imeyileFilter.test (tfld)) {// vavanya i-imeyile ngoonobumba abangavumelekanga

    Impazamo = "Nceda ngenisa idilesi ye-imeyile eyiyo.n";
    } Enye into ukuba (fld.value.match (iChars engekho mthethweni)) {

    Impazamo = "Nceda ngenisa idilesi ye-imeyile eyiyo.n";
    }
    buyisela impazamo;
    }

  22. 31

    Umsebenzi uqinisekisa i-imeyile (fld) {
    var impazamo = "";
    I-var tfld = i-trim (ixabiso le-fld); // Ixabiso lendawo enendawo emhlophe ecinyiweyo
    var emailFilter = / ^ [^@ ]+@@ ^^@. ]+. [^@ ]*ww$/;
    var engekho mthethweniChars = / [(),;: \ ”[]] /;

    ukuba (fld.value == "Ngenisa idilesi yemeyile yakho") {

    Impazamo = "Nceda ufake idilesi ye-imeyile.n";
    } Enye into ukuba (! imeyileFilter.test (tfld)) {// vavanya i-imeyile ngoonobumba abangavumelekanga

    Impazamo = "Nceda ngenisa idilesi ye-imeyile eyiyo.n";
    } Enye into ukuba (fld.value.match (iChars engekho mthethweni)) {

    Impazamo = "Nceda ngenisa idilesi ye-imeyile eyiyo.n";
    }
    buyisela impazamo;
    }

  23. 32

    Umsebenzi uqinisekisa i-imeyile (fld) {
    var impazamo = "";
    I-var tfld = i-trim (ixabiso le-fld); // Ixabiso lendawo enendawo emhlophe ecinyiweyo
    var emailFilter = / ^ [^@ ]+@@ ^^@. ]+. [^@ ]*ww$/;
    var engekho mthethweniChars = / [(),;: \ ”[]] /;

    ukuba (fld.value == "Ngenisa idilesi yemeyile yakho") {

    Impazamo = "Nceda ufake idilesi ye-imeyile.n";
    } Enye into ukuba (! imeyileFilter.test (tfld)) {// vavanya i-imeyile ngoonobumba abangavumelekanga

    Impazamo = "Nceda ngenisa idilesi ye-imeyile eyiyo.n";
    } Enye into ukuba (fld.value.match (iChars engekho mthethweni)) {

    Impazamo = "Nceda ngenisa idilesi ye-imeyile eyiyo.n";
    }
    buyisela impazamo;
    }

  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.