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 ke hana class="emailaddress". Inā loaʻa iā ʻoe ka hale waihona prototype.js (http://www.prototypejs.org) 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})+$/;
    $$('.emaildress').kekahi(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;
    pono = wahahee;
    }
    });
    hoʻihoʻi kūpono;

  2. 5
  3. 7

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

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

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

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

    • 8

      Aloha Reg,

      Hiki iā ʻoe ke hoʻāʻo i ka Regex me ka hoʻohana ʻana i kahi Hōʻike Regex Online.

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

      Aia kekahi mau kumu e ʻae ʻole ai i kekahi e hoʻokomo i kahi leka uila kūpono ʻole:
      1. E huhū lākou iā ʻoe ke loaʻa ʻole ka leka uila a lākou i manaʻo ai - inā ʻaʻole ʻoe i hewa i ka hoʻokomo hewa ʻana i ka helu wahi.
      2. Inā he kahua kūpono ka com.museum a, e ʻōlelo kākou, Yahoo! hoʻohana ia - ʻo kēlā me kēia leka uila i hoʻopaʻa ʻia he hopena maikaʻi ʻole ia i ka inoa o kāu hui no ka lawe ʻana i ka leka uila. Hiki i kēia ke hoʻopaʻa ʻia nā leka uila a pau o kāu hui.
      3. Inā ʻae kāu mea lawelawe leka uila iā ʻoe e komo bob@com.museum, e uku nō hoʻi ʻoe no kēlā me kēia leka uila i hoʻouna ʻia i kēlā helu leka uila a hiki i ka wā i kāpae ai lākou i kēlā helu helu ma muli o nā bounce. E hoʻokele wau i kekahi ESP e ʻae i kahi leka uila hewa ʻole e like me ia - ke lawe wale nei lākou i kāu kālā!

      Mahalo no ka pau ʻana e!
      Doug

  4. 9
  5. 10

    Aia kekahi ala maʻalahi e kākau i ka ʻōlelo:
    var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
    – Me ka mea hoʻololi hope /i ʻaʻole pono e hōʻike i ka laulā huahelu kiʻekiʻe.
    – ʻAʻole au i ʻike i kekahi TLD me nā helu i loko.
    Ma ka ʻaoʻao ʻaoʻao, ʻae wau iā TLD me nā 6 chars; Hiki mai nā mea hou a ʻaʻole ʻoe i ʻike (maikaʻi, aia kekahi mau helu i ka wā e hiki mai ana, ʻike wau).

  6. 11

    Aloha,

    Ke hoʻāʻo nei au e hoʻohana i kēia ma kahi ʻano i loaʻa i ka manawa maoli, akā ʻaʻole ʻike ʻia kēia e hōʻoia i ka manawa maoli e like me kāu mākaʻikaʻi ikaika ʻōlelo huna…

    A i ʻole, ʻaʻole maopopo iaʻu, a ʻaʻole hana ia iaʻu?

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

    ʻO kahi hoʻoponopono liʻiliʻi wale nō: Loaʻa ka ʻōlelo maʻamau ()+ ma ka hopena. Pono e heluhelu:

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

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

  11. 18

    Hiki iā ʻoe ke wehewehe i ka ʻōlelo maʻamau o kēia code a pehea e hana ai? E pili ana hoʻi i ka .test - ʻO .test kahi ʻōlelo maʻamau i 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 validateEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{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 validateEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    hoʻihoʻi i ka leka uilaPattern.test(id);

    }
    Deepak Rai
    ʻo ia

  14. 21
  15. 22
  16. 23

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

    hoao@ hoao

    a ua hala i ka regex… ʻike wau ʻaʻole i pakele i ka "." no laila pono:

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

  17. 24
  18. 27

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

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

    No ka ʻike e pili ana i nā 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:

    hana validateEmail(id)
    {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    hoʻihoʻi i ka leka uilaPattern.test(id);

    }

    A i ʻole, ʻo ke kiko ke ʻano "kekahi ʻano". Ke manaʻoʻiʻo nei au e pono e pakele ia mau mea kūikawā.

    ka nānā 'ole,

    Federico

  20. 29

    hana validateEmail(fld) {
    var hewa = "";
    var tfld = ʻoki(fld.value); // waiwai o ke kahua me ke keʻokeʻo i ʻoki ʻia
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

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

    error = "E ʻoluʻolu e hoʻokomo i kāu leka uila.n";
    } 'ē aʻe inā (!emailFilter.test(tfld)) {/ //e hoʻāʻo i ka leka uila no nā huaʻōlelo kūpono ʻole

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

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

  21. 30

    hana validateEmail(fld) {
    var hewa = "";
    var tfld = ʻoki(fld.value); // waiwai o ke kahua me ke keʻokeʻo i ʻoki ʻia
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

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

    error = "E ʻoluʻolu e hoʻokomo i kāu leka uila.n";
    } 'ē aʻe inā (!emailFilter.test(tfld)) {/ //e hoʻāʻo i ka leka uila no nā huaʻōlelo kūpono ʻole

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

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

  22. 31

    hana validateEmail(fld) {
    var hewa = "";
    var tfld = ʻoki(fld.value); // waiwai o ke kahua me ke keʻokeʻo i ʻoki ʻia
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

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

    error = "E ʻoluʻolu e hoʻokomo i kāu leka uila.n";
    } 'ē aʻe inā (!emailFilter.test(tfld)) {/ //e hoʻāʻo i ka leka uila no nā huaʻōlelo kūpono ʻole

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

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

  23. 32

    hana validateEmail(fld) {
    var hewa = "";
    var tfld = ʻoki(fld.value); // waiwai o ke kahua me ke keʻokeʻo i ʻoki ʻia
    var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
    var illegalChars= /[(),;:\”[]]/ ;

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

    error = "E ʻoluʻolu e hoʻokomo i kāu leka uila.n";
    } 'ē aʻe inā (!emailFilter.test(tfld)) {/ //e hoʻāʻo i ka leka uila no nā huaʻōlelo kūpono ʻole

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

    error = "E ʻoluʻolu e hoʻokomo i kahi leka uila kūpono.n";
    }
    hoʻihoʻ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.