Onani Imelo Adilesi ndi JavaScript ndi Mawu Okhazikika

Kanthawi kapitako ndidayika Chitsimikizo Cha Mphamvu Yachinsinsi pogwiritsa ntchito JavaScript ndi Mawu Okhazikika. Patsamba lomweli, mutha kuyang'ananso kapangidwe ka imelo pogwiritsa ntchito njira yomweyo (regex).

Ngati mawonekedwe anu ali ndi id = "imelo adilesi" ndipo muwonjezera fomu onSubmit = "kubwerera checkEmail ();", Iyi ndi ntchito ya Javascript yomwe mungagwiritse ntchito kubwezera chenjezo ngati imelo ili ndi mtundu woyenera kapena ayi:

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

Ntchitoyi imatsimikizira zomwe zili mu imelo ndi zosefera. Ngati kufananirako kwalephera, kumatulutsa chenjezo ndikubwezeretsanso zomwezo ku adilesi ya imelo!

41 Comments

  1. 1

    Kwa mafomu omwe ali ndi ma adilesi angapo amaimelo, zingakhale bwino kuchita class = "emailaddress". Ngati muli ndi laibulale ya prototype.http://www.prototypejs.org) kuphatikiza patsamba mutha kuchita izi:

    var chomveka = chowonadi;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    $$ ('. emailaddress'). iliyonse (ntchito (imelo) {
    ngati (! filter.test (email.value)) {
    chenjezo (? Chonde perekani imelo adilesi yolondola?);
    imelo.focus;
    chomveka = zabodza;
    }
    });
    kubwerera kuli koyenera;

  2. 5
  3. 7

    Ndimakonda lingalirolo, koma sindingakhale womvera kutengera mawuwa nthawi zonse osafotokoza kuti ndi maimelo ati omwe sawalandila kapena ma adilesi ovomerezeka omwe amalola.

    Mwachitsanzo cha mafotokozedwe anthawi zonse omwe amagwira ntchito yabwino kuphatikiza malongosoledwe amomwe sanakhudzidwe, onani izi:

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

    Zokonda zanga ndikuphimba milandu yosavuta yambiri ndikupereka chenjezo la china chilichonse m'malo mochikana. Ngati Bob akufunadi kuti apereke bob@com.museum m'malo moti bob@museum.com, bwanji osamulola?

    • 8

      Moni Reg,

      Mutha kuyesa Regex pogwiritsa ntchito Woyesa Regex pa intaneti.

      Komanso, pali zambiri zomwe zingachitike ngati mukufuna kutsimikiza fayilo ya imelo adilesi ndiyovomerezeka malinga ndi RFC.

      Pali zifukwa zingapo zosalola kuti wina alowe mu imelo yolakwika:
      1. Adzakukwiyirani pamene imelo yomwe amayembekeza kuti siyidutse - mosasamala kanthu kuti munalakwitsa adilesiyo kuti sinayimidwe molondola.
      2. Ngati com.museum inali malo ovomerezeka ndipo, tinene kuti, Yahoo! idayigwiritsa ntchito - imelo iliyonse yomwe imabweza imatha kukhala ndi vuto pakampani yanu potumiza maimelo. Izi zitha kupangitsa kuti imelo yonse ya kampani yanu itsekedwe.
      3. Ngati wothandizira maimelo akuloleza kulowa bob@com.museum, mumalipiranso imelo iliyonse yomwe imatumizidwa ku imeloyo mpaka atalembetsa adilesiyi chifukwa chobedwa. Ndikadakhala kutali ndi ESP iliyonse yomwe ingalole kuti maimelo osagwira ngati amenewo - akungotenga ndalama zanu!

      Zikomo chifukwa chadutsa!
      Doug

  4. 9
  5. 10

    Pali njira yosavuta yolembera mawuwa:
    var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
    - Ndikusintha komaliza / i palibe chifukwa chofotokozera mulingo wapamwamba.
    - Sindikudziwa chilichonse TLD ndi manambala mmenemo.
    Pazolemba, ndimalola TLD kukhala ndi zida mpaka 6; zatsopano zimabwera pafupipafupi ndipo simukudziwa (chabwino, ena mtsogolo atha kukhala ndi manambala, ndikudziwa).

  6. 11

    Muno kumeneko,

    Ndikuyesera kugwiritsa ntchito izi mu mawonekedwe omwe alipo munthawi yeniyeni, koma izi sizikuwoneka ngati zikuwunika munthawi yeniyeni ngati chiphaso chanu chachinsinsi ...

    Kapena, kodi ndili chabe wopanda nzeru, ndipo sizingandithandize?

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

    Kuwongolera kwakung'ono: Mawu wamba amakhala ndi zowonjezera () + kumapeto. Iyenera kuwerenga:

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

    Ndi woyamba kutalika ma TLD onse angavomerezedwe (zomwe sizolakwika kwambiri monga ena ananenera, koma ngati icho chinali cholinga mawuwo akhoza kufupikitsidwa).

  11. 18

    Kodi chonde mungafotokozere mafotokozedwe amtunduwu komanso momwe amagwirira ntchito? Komanso za .test - Kodi .test mawu osasinthika mu javascript kuti muwone zinthu zomwe mudachita mu code ili pamwambapa?

  12. 19

    Nambala yachidule yofotokozera imelo-

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

    }
    Deepak Rai
    varanasi

  13. 20

    Nambala yachidule yofotokozera imelo-

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

    }
    Deepak Rai
    varanasi

  14. 21
  15. 22
  16. 23

    Zikomo, koma pali vuto mu regex iyi. Sindine katswiri wa regex, koma ndimayesa imelo:

    mayeso @ test

    ndipo idadutsa regex ... ndidazindikira kuti ikusowa "." zikhale choncho:

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

  17. 24
  18. 27

    Ichi ndi cheke chokhwima koma osalondola 100%, mwachitsanzo izi zikhala bwino nazo @alirezatalischioriginal yomwe siyimelo adilesi yolondola (kadontho sikuloledwa ngati munthu womaliza m'mbali imelo).
    Komanso imavomereza john ...... chomwenso ndichosavomerezeka popeza sipangakhale dontho lopitilira limodzi motsatizana.

    Izi ndi zina mwa zolakwika zomwe ndidaziwona pakuwona koyamba.
    Cholinga changa sikungokhalira kungonena izi mwina wina akukonzekera kugwiritsa ntchito izi ngati cheke chachitetezo - osatetezedwa mokwanira.

    Kuti mumve zambiri za ma adilesi amaimelo ovomerezeka onani izi: http://en.wikipedia.org/wiki/E-mail_address

  19. 28

    Deepak, PA

    M'malo mwake, ndikuganiza kuti muyenera kuyikapo potumiza dontho ("."). Chifukwa chake, ntchito yanu iyenera kukhala, m'malo mwake:

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

    }

    Kupanda kutero, dontho limatanthauza "mawonekedwe aliwonse". Ndikukhulupirira otchulidwa apaderawa amafunika kuthawa.

    Nkhani,

    Federico

  20. 29

    ntchito yambitsiraniEmail (fld) {
    var zolakwa = "";
    var tfld = chepetsa (fld.value); // mtengo wamunda wokhala ndi whitespace wadulidwa
    var emailFilter = / ^ [^@ ]+@ [^^ @. ]+. [^@ ]*ww$/;
    var malamuloChars = / [(),;: \ ”[]] /;

    ngati (fld.value == "Lowetsani Imelo Adilesi Yanu") {

    error = "Chonde lowetsani Imelo adilesi yanu.n";
    } china ngati (! emailFilter.test (tfld)) {// kuyesa imelo ya zilembo zosaloledwa

    error = "Chonde lowetsani imelo adilesi yolondola.n";
    } china ngati (fld.value.match (zosemedwaChars)) {

    error = "Chonde lowetsani imelo adilesi yolondola.n";
    }
    zolakwika zobwerera;
    }

  21. 30

    ntchito yambitsiraniEmail (fld) {
    var zolakwa = "";
    var tfld = chepetsa (fld.value); // mtengo wamunda wokhala ndi whitespace wadulidwa
    var emailFilter = / ^ [^@ ]+@ [^^ @. ]+. [^@ ]*ww$/;
    var malamuloChars = / [(),;: \ ”[]] /;

    ngati (fld.value == "Lowetsani Imelo Adilesi Yanu") {

    error = "Chonde lowetsani Imelo adilesi yanu.n";
    } china ngati (! emailFilter.test (tfld)) {// kuyesa imelo ya zilembo zosaloledwa

    error = "Chonde lowetsani imelo adilesi yolondola.n";
    } china ngati (fld.value.match (zosemedwaChars)) {

    error = "Chonde lowetsani imelo adilesi yolondola.n";
    }
    zolakwika zobwerera;
    }

  22. 31

    ntchito yambitsiraniEmail (fld) {
    var zolakwa = "";
    var tfld = chepetsa (fld.value); // mtengo wamunda wokhala ndi whitespace wadulidwa
    var emailFilter = / ^ [^@ ]+@ [^^ @. ]+. [^@ ]*ww$/;
    var malamuloChars = / [(),;: \ ”[]] /;

    ngati (fld.value == "Lowetsani Imelo Adilesi Yanu") {

    error = "Chonde lowetsani Imelo adilesi yanu.n";
    } china ngati (! emailFilter.test (tfld)) {// kuyesa imelo ya zilembo zosaloledwa

    error = "Chonde lowetsani imelo adilesi yolondola.n";
    } china ngati (fld.value.match (zosemedwaChars)) {

    error = "Chonde lowetsani imelo adilesi yolondola.n";
    }
    zolakwika zobwerera;
    }

  23. 32

    ntchito yambitsiraniEmail (fld) {
    var zolakwa = "";
    var tfld = chepetsa (fld.value); // mtengo wamunda wokhala ndi whitespace wadulidwa
    var emailFilter = / ^ [^@ ]+@ [^^ @. ]+. [^@ ]*ww$/;
    var malamuloChars = / [(),;: \ ”[]] /;

    ngati (fld.value == "Lowetsani Imelo Adilesi Yanu") {

    error = "Chonde lowetsani Imelo adilesi yanu.n";
    } china ngati (! emailFilter.test (tfld)) {// kuyesa imelo ya zilembo zosaloledwa

    error = "Chonde lowetsani imelo adilesi yolondola.n";
    } china ngati (fld.value.match (zosemedwaChars)) {

    error = "Chonde lowetsani imelo adilesi yolondola.n";
    }
    zolakwika zobwerera;
    }

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

Mukuganiza chiyani?

Tsambali likugwiritsa ntchito Akismet kuchepetsa spam. Phunzirani momwe deta yanu ikufotokozera.