E hōʻoia i ka leka uila me ka JavaScript a me nā ʻōlelo maʻamau

I kekahi manawa i hala iho nei ua kau wau i ʻO ka Checker ikaika ʻōlelo huna me ka hoʻohana ʻana iā JavaScript a me nā Manaʻo mau. Ma kēlā memo like, hiki iā ʻoe ke nānā i ke ʻano o kahi leka uila e hoʻohana ana i ka hana like (regex) ʻano like.

Inā loaʻa i kāu mea hana ka id = "leka uila" a hoʻohui ʻoe i kahi palapala onSubmit = "hōʻoia hōʻoiaEmail ();, He hana Javascript kēia e hiki ai iā ʻoe ke hoʻohana no ka hoʻihoʻi ʻana i kahi leka inā loaʻa kahi hanana kūpono i ka leka uila:

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

Hoʻohana ka hana i nā ʻike o ka leka uila i kēlā o ka kānana. Inā holo ʻole ka hoʻohālikelike, pops ia i kahi ala a hoʻi i ka nānā i ka ʻaoʻao o ka leka uila.

41 Comments

  1. 1

    No nā palapala me nā helu leka uila he nui, maikaʻi e hana i ka papa = "leka uila". Inā loaʻa iā ʻoe ka prototype.js waihona (http://www.prototypejs.org) hoʻokomo ʻia ma ka ʻaoʻao hiki iā ʻoe ke hana i kekahi mea e like me kēia:

    var valid = ʻoiaʻiʻo;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    $$ ('. emailaddress'). kēlā me kēia (hana (leka uila) {
    inā (! filter.test (email.value)) {
    makaʻala (? E ʻoluʻolu e hāʻawi i kahi leka uila kūpono?);
    leka uila.focus;
    pololei = wahaheʻe;
    }
    });
    hoʻihoʻi kūpono;

  2. 5
  3. 7

    Makemake wau i ka manaʻo, akā kānalua wau e hoʻohana i kēia ʻōlelo maʻamau maʻamau me ka ʻole o ka wehewehe ʻana o nā leka uila kū kānāwai i ʻae ʻole ʻia a me nā kamaʻilio kolohe i ʻae ʻia

    No kahi laʻana o kahi hōʻike maʻamau e hana nei i kahi hana kūpono me ka wehewehe o nā hihia ʻaʻole ia e uhi, e ʻike i kēia:

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

    ʻO kaʻu makemake pilikino ka uhi ʻana i ka hapa nui o nā hihia maʻalahi a hoʻopuka i kahi ʻōlelo aʻoaʻo no nā mea āpau ma mua o ka hōʻole ʻana. Inā makemake maoli ʻo Bob e hoʻouna bob@com.museum ma kahi o bob@museum.com, no ke aha e hoʻokuʻu ʻole ai iā ia?

    • 8

      Aloha Reg,

      Hiki iā ʻoe ke hōʻoia i ka Regex e hoʻohana nei i kahi Hoʻokolohua Regex Pūnaewele.

      Eia kekahi, ʻoi aku ka nui o nā mea i hiki ke hana inā makemake ʻoe e hōʻoia i helu leka uila kūpono e like me ka RFC.

      Aia kekahi mau kumu i ʻae ʻole i kekahi e komo i kahi leka uila kūpono ʻole:
      1. E huhū mai lākou iā ʻoe ke hele ʻole ka leka uila a lākou e manaʻo ai - no ka hewa a hewa ʻole paha kāu kuhi hewa ʻana.
      2. Inā he kikowaena kūpono ka com.museum a, e ʻōlelo kākou, Yahoo! hana ia - kekahi leka uila i kūʻē mai e loaʻa ka hopena maikaʻi ʻole i ka inoa o kāu ʻoihana no ka hoʻouna leka uila. Hiki iā ia ke alakaʻi i kāu mau leka uila āpau e ālai ʻia.
      3. Inā ʻae kāu mea lawelawe leka uila iā ʻoe e komo bob@com.museum, uku ʻoe no kēlā me kēia leka uila i hoʻouna ʻia i kēlā leka uila a hiki i ka wā i kākau inoa ʻia ai lākou i kēlā helu wahi ma muli o ka lele ʻana. E hoʻokele wau i kahi ESP e ʻae i kahi leka uila kūpono ʻole e like me kēlā - ke lawe nei lākou i kāu kālā!

      Mahalo no ka pau ʻana e!
      Doug

  4. 9
  5. 10

    Aia kahi ala maʻalahi e kākau i ka manaʻo:
    var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
    - Me ka mea hoʻololi hope loa / ʻaʻole pono e hōʻike i ka pae kiʻekiʻe.
    - ʻAʻole maopopo iaʻu TLD me nā helu i loko.
    Ma kahi leka ʻaoʻao, ʻae wau iā TLD a hiki i 6 chars; hōʻea mau nā mea hou a ʻaʻole ʻoe ʻike (ʻē, e loaʻa paha nā helu i ka wā e hiki mai ana i loko, ʻike wau).

  6. 11

    Aloha,

    Keʻike nei wau e hoʻohana i kēia i kahi ʻano i kēia manawa i ka manawa maoli, akā ʻike ʻole ʻia ke hōʻoia nei i ka manawa hou e like me kāu hōʻoia ikaika ʻōlelo huna ...

    A i ʻole, he clueless wale nō wau, a hana ia naʻu?

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

    ʻO kahi hoʻoponopono liʻiliʻi wale nō: He keu ka huaʻōlelo maʻamau () + ma ka hopena. E heluhelu ia:

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

    Me ka mea mua i kekahi lōʻihi e ʻae ʻia nā TLD (ʻaʻole hewa hewa ʻole e like me ka haʻi ʻana, akā inā ʻo ia ka manaʻo hiki ke hoʻopōkole ʻia ka ʻōlelo).

  11. 18

    Hiki iā ʻoe ke ʻoluʻolu e wehewehe i ka hōʻike maʻamau o kēia code a pehea e hana ai? Eia kekahi e pili ana i .test - He ʻōlelo paʻamau .test i loko o ka javascript e nānā i nā mea e like me kāu i hana ai ma ke code ma luna?

  12. 19

    He code pōkole kēia no ka hōʻike leka uila-

    hana e hōʻoia iāEmail (id)
    {
    var emailPattern = /^[a-zA-Z0-9._-gris+@[a-zA-Z0-9.-gris+.[a-zA-Zopito{2,4}$/;
    hoʻihoʻi i ka leka uilaPattern.test (id);

    }
    Deepak Rai
    ʻo ia

  13. 20

    He code pōkole kēia no ka hōʻike leka uila-

    hana e hōʻoia iāEmail (id)
    {
    var emailPattern = /^[a-zA-Z0-9._-gris+@[a-zA-Z0-9.-gris+.[a-zA-Zopito{2,4}$/;
    hoʻihoʻi i ka leka uilaPattern.test (id);

    }
    Deepak Rai
    ʻo ia

  14. 21
  15. 22
  16. 23

    Mahalo, akā aia kekahi hemahema i kēia regex. ʻAʻole wau he loea regex, akā ua hoʻāʻo wau i ka leka uila:

    hoʻāʻo @ hoʻāʻo

    a hala i ka regex ... ua ʻike au i ka nalo ʻana mai ka pakele ʻana i ka "." no laila pono ia:

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

  17. 24
  18. 27

    ʻĀ, he kaha kaha koʻikoʻi wale kēia akā ʻaʻole 100% pololei, no ka laʻana he maikaʻi kēia me john_doe. @ gmail.com ʻaʻole ia he helu leka uila kūpono (ʻaʻole ʻae ʻia ka kiko ma ke ʻano he ʻano hope loa i kahi ʻāpana o ka leka uila.
    E ʻae nō hoʻi ia john…doe@gmail.com ʻo ia hoʻi he hewa ʻole ma muli o ka hiki ʻole ke ʻoi aku i hoʻokahi kiko i ke kaʻina.

    He mau hemahema wale nō kēia aʻu i ʻike ai i ka maka mua.
    ʻAʻole kuʻu manaʻo i ka bashing e kuhikuhi wale i kēia inā e hoʻolālā ana kekahi e hoʻohana i kēia ma ke ʻano he palekana - ʻaʻole lawa ka paʻa.

    No ka ʻike e pili ana i nā helu leka uila kūpono e nānā i kēia: http://en.wikipedia.org/wiki/E-mail_address

  19. 28

    Deepak,

    ʻOiaʻiʻo, manaʻo wau pono ʻoe e noi i kahi pakele no ke kiko ("."). No laila, pono kāu hana, ma kahi o:

    hana e hōʻoia iāEmail (id)
    {
    var emailPattern = /^[a-zA-Z0-9._-gris+@[a-zA-Z0-9.-gris+.[a-zA-Zopito{2,4}$/;
    hoʻihoʻi i ka leka uilaPattern.test (id);

    }

    Inā ʻole, ke ʻano o ke kiko "kekahi ʻano". Manaʻo wau e pono e pakele i nā ʻano kūikawā.

    ka nānā 'ole,

    Federico

  20. 29

    hana e hōʻoia iāEmail (fld) {
    var error = "";
    var tfld = ʻoki (fld.value); // waiwai o ka pā kula me ka keʻokeʻo keʻokeʻo
    var emailFilter = /^[ ^^@<<+@[^@.<<+.[^@<<*ww$/;
    var illegalChars = / [(),;: \ ”[]] /;

    inā (fld.value == "E hoʻokomo i kāu leka uila") {

    hewa = "E hoʻokomo i kāu leka uila.n";
    } ʻē aʻe inā (! emailFilter.test (tfld)) {// hōʻoia leka uila no nā huapalapala kū kānāwai ʻole

    hewa = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    } ʻē aʻe inā (fld.value.match (illegalChars)) {

    hewa = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    }
    hoʻi hewa;
    }

  21. 30

    hana e hōʻoia iāEmail (fld) {
    var error = "";
    var tfld = ʻoki (fld.value); // waiwai o ka pā kula me ka keʻokeʻo keʻokeʻo
    var emailFilter = /^[ ^^@<<+@[^@.<<+.[^@<<*ww$/;
    var illegalChars = / [(),;: \ ”[]] /;

    inā (fld.value == "E hoʻokomo i kāu leka uila") {

    hewa = "E hoʻokomo i kāu leka uila.n";
    } ʻē aʻe inā (! emailFilter.test (tfld)) {// hōʻoia leka uila no nā huapalapala kū kānāwai ʻole

    hewa = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    } ʻē aʻe inā (fld.value.match (illegalChars)) {

    hewa = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    }
    hoʻi hewa;
    }

  22. 31

    hana e hōʻoia iāEmail (fld) {
    var error = "";
    var tfld = ʻoki (fld.value); // waiwai o ka pā kula me ka keʻokeʻo keʻokeʻo
    var emailFilter = /^[ ^^@<<+@[^@.<<+.[^@<<*ww$/;
    var illegalChars = / [(),;: \ ”[]] /;

    inā (fld.value == "E hoʻokomo i kāu leka uila") {

    hewa = "E hoʻokomo i kāu leka uila.n";
    } ʻē aʻe inā (! emailFilter.test (tfld)) {// hōʻoia leka uila no nā huapalapala kū kānāwai ʻole

    hewa = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    } ʻē aʻe inā (fld.value.match (illegalChars)) {

    hewa = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    }
    hoʻi hewa;
    }

  23. 32

    hana e hōʻoia iāEmail (fld) {
    var error = "";
    var tfld = ʻoki (fld.value); // waiwai o ka pā kula me ka keʻokeʻo keʻokeʻo
    var emailFilter = /^[ ^^@<<+@[^@.<<+.[^@<<*ww$/;
    var illegalChars = / [(),;: \ ”[]] /;

    inā (fld.value == "E hoʻokomo i kāu leka uila") {

    hewa = "E hoʻokomo i kāu leka uila.n";
    } ʻē aʻe inā (! emailFilter.test (tfld)) {// hōʻoia leka uila no nā huapalapala kū kānāwai ʻole

    hewa = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    } ʻē aʻe inā (fld.value.match (illegalChars)) {

    hewa = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    }
    hoʻi hewa;
    }

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

Pehea kou manaʻo?

Ke hoʻohana nei kēia pūnaewele i ka Akismet e ho'ēmi i ka spam. E aʻo pehea e hanaʻia ai kāuʻikeʻikepili.