Bincika Adireshin Imel tare da JavaScript da maganganun yau da kullun

Wani lokaci da suka wuce na sanya a Mai Duba rearfin Password ta amfani da JavaScript da Maganganu na Yau da kullun. A waccan bayanin kula, zaku iya bincika tsarin adireshin imel ta hanyar amfani da hanya iri ɗaya (regex).

Idan nau'ikan nau'ikanku yana da id = ”adireshin imel” kuma kun kara fom onSubmit = ”dawo da adireshi ();“, Wannan aikin Javascript ne wanda zaku iya amfani dashi don dawo da faɗakarwa idan adireshin imel ɗin yana da ingantaccen tsari ko a'a:

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

Aikin yana inganta abubuwan da ke cikin imel ɗin zuwa na tace. Idan kwatancen ya gaza, zai tashi faɗakarwa kuma ya mayar da hankali zuwa filin adireshin imel!

41 Comments

  1. 1

    Ga siffofin da adiresoshin imel da yawa, zai yi kyau a yi aji = ”emailaddress”. Idan kuna da dakin karatu na farko.js (http://www.prototypejs.org) wanda aka hada a shafin zaka iya yin abu kamar haka:

    var valid = gaskiya ne;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    $ $ ('. emailaddress'). kowane (aiki (email) {
    idan (! tace. gwajin (email.value)) {
    faɗakarwa (? Da fatan za a samar da adireshin imel mai inganci?);
    email.ci hankali;
    ingantacce = karya;
    }
    });
    dawowa ingantacce;

  2. 5
  3. 7

    Ina son ra'ayin, amma zan yi jinkirin yin amfani da wannan magana ta yau da kullun ba tare da bayanin adiresoshin imel ɗin da ba ta karɓa ba da kuma adiresoshin da ba ta doka ba.

    Misali na magana ta yau da kullun wanda ke aiki mai kyau tare da bayanin abin da batutuwa ba ta shafi, ga wannan:

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

    Abinda na fi so shi ne in rufe mafi yawan lokuta kuma inyi gargadi ga komai maimakon kin amincewa dashi. Idan Bob da gaske yana son tsayawa bob@com.museum maimakon bob@museum.com, me zai hana a barshi?

    • 8

      Sannu Reg,

      Kuna iya gwada Regex ta amfani da Gwajin Regex na Yanar gizo.

      Hakanan, tabbas akwai abubuwa da yawa da za a iya yi idan kuna son tabbatarwa adireshin i-mel yana aiki daidai da RFC.

      Akwai wasu 'yan dalilai da zasu hana mutum ya shigar da adireshin imel mara inganci:
      1. Zasu fusata da kai lokacin da imel din da suke tsammani bai samu ba - ba tare da la’akari da cewa ko kuma laifin ka ne an shigar da adireshin kuskure.
      2. Idan com.museum ya kasance yanki ne mai inganci kuma, a ce, Yahoo! sarrafa shi - kowane adireshin imel ɗin da ya bunƙasa zai haifar da mummunan tasiri ga mutuncin kamfanin ku don isar da imel. Wannan na iya haifar da toshe duk imel ɗin kamfanin ku.
      3. Idan mai baka email ya baka damar shiga bob@com.museum, Zaka kuma biya kowane imel da aka aika zuwa adireshin imel ɗin har sai sun cire rajistar adireshin saboda yawan kuɗi. Zan kauce daga kowane ESP wanda zai ba da izinin adireshin imel mara inganci kamar haka - suna karɓar kuɗin ku ne kawai!

      Godiya don tsayawa ta!
      Doug

  4. 9
  5. 10

    Akwai hanya mafi sauki don rubuta kalmar:
    var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
    - Tare da mai gyara na karshe / i babu buƙatar nuna kewayon babban lamarin.
    - Ban san ko daya ba TLD tare da lambobi a ciki.
    A bayanin kula na gefe, na kyale TLD tare da har zuwa chars 6; sababbi suna zuwa a kai a kai kuma baku sani ba (da kyau, wasu masu zuwa ma suna iya samun lambobi a ciki, na sani).

  6. 11

    Sannu dai,

    Ina tring don amfani da wannan a cikin hanyar data kasance a ainihin lokacin, amma wannan baya bayyana yana inganta a ainihin lokacin kamar mai duba kalmar sirri…

    Ko kuwa, ni kawai wannan ba shi da ma'ana, kuma ba shi da amfani a gare ni?

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

    Correctionan ƙaramin gyara: Maganar yau da kullun tana da ƙarin () + a ƙarshen. Ya kamata a karanta:

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

    Tare da na farko za'a karɓi kowane TLDs (wanda ba laifi bane a cikin sirri kamar yadda wasu suka nuna, amma idan wannan shine manufar ana iya gajarta magana).

  11. 18

    Shin zaku iya bayanin yadda ake nuna wannan lambar yau da kullun da kuma yadda take aiki? Har ila yau game da. Gwada - Shin. Gwada tsoffin bayani a cikin javascript don bincika abubuwa kamar yadda kuka yi a cikin lambar da ke sama?

  12. 19

    Wannan gajeriyar hanya ce don bayyanar da imel-

    ingantaccen aiki Imel (id)
    {
    var emailPattern = / ^-a-zA-Z0-9._-] +@=a-zA-Z0-9.-].
    dawo da emailPattern.test (id);

    }
    Deepak Rai
    varanasi

  13. 20

    Wannan gajeriyar hanya ce don bayyanar da imel-

    ingantaccen aiki Imel (id)
    {
    var emailPattern = / ^-a-zA-Z0-9._-] +@=a-zA-Z0-9.-].
    dawo da emailPattern.test (id);

    }
    Deepak Rai
    varanasi

  14. 21
  15. 22
  16. 23

    Godiya, amma akwai kuskure a cikin wannan regex. Ni ba masanin regex bane, amma nayi kokarin imel:

    gwada @ gwada

    kuma ta wuce regex… Na lura bata da tserewa daga "." don haka ya kamata:

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

  17. 24
  18. 27

    Da kyau, wannan duba ne kawai amma ba 100% daidai ba, misali wannan zai zama daidai da john_doe. @ gmail.com wanda a zahiri ba ingantaccen adireshin e-mail bane (ba a yarda dot ba a matsayin halayyar ƙarshe a ɓangaren e-mail na gida).
    Hakanan zai yarda john…doe@gmail.com wanda kuma ba shi da inganci tunda ba za a iya samun sama da ɗigo ɗaya a cikin jerin ba.

    Waɗannan kawai wasu lahani ne da na lura da su a farkon gani.
    Nufina ba ya girgiza don kawai in nuna wannan idan wani yana shirin yin amfani da wannan azaman binciken tsaro - ba amintaccen isa ba.

    Don bayani game da ingantattun adiresoshin e-mail duba wannan: http://en.wikipedia.org/wiki/E-mail_address

  19. 28

    Deepak,

    A gaskiya, Ina tsammanin kuna buƙatar amfani da hanyar tserewa don ɗigon ("."). Don haka, aikinku ya zama, a maimakon haka:

    ingantaccen aiki Imel (id)
    {
    var emailPattern = / ^-a-zA-Z0-9._-] +@=a-zA-Z0-9.-].
    dawo da emailPattern.test (id);

    }

    In ba haka ba, digon zai iya nufin “kowane hali”. Na yi imanin irin waɗannan halayen na musamman suna buƙatar tserewa.

    gaisuwa,

    Federico

  20. 29

    ingantaccen aiki Email (fld) {
    var error = ””;
    var tfld = datsa (fld.value); // darajar filin tare da sararin samaniya an datse shi
    var emailFilter = / ^^^]]]]]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/
    var illegalChars = / [(),;: \ ”[]] /;

    idan (fld.value == "Shigar da Adireshin imel ɗin ku") {

    kuskure = “Da fatan za a shigar da adireshin Imel ɗin ku.n”;
    } in kuma idan (! emailFilter.test (tfld)) {// imel gwajin don haruffan doka

    kuskure = “Da fatan za a shigar da adireshin imel mai inganci.n”;
    } in kuma idan (fld.value.match (illegalChars)) {

    kuskure = “Da fatan za a shigar da adireshin imel mai inganci.n”;
    }
    komowar kuskure;
    }

  21. 30

    ingantaccen aiki Email (fld) {
    var error = ””;
    var tfld = datsa (fld.value); // darajar filin tare da sararin samaniya an datse shi
    var emailFilter = / ^^^]]]]]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/
    var illegalChars = / [(),;: \ ”[]] /;

    idan (fld.value == "Shigar da Adireshin imel ɗin ku") {

    kuskure = “Da fatan za a shigar da adireshin Imel ɗin ku.n”;
    } in kuma idan (! emailFilter.test (tfld)) {// imel gwajin don haruffan doka

    kuskure = “Da fatan za a shigar da adireshin imel mai inganci.n”;
    } in kuma idan (fld.value.match (illegalChars)) {

    kuskure = “Da fatan za a shigar da adireshin imel mai inganci.n”;
    }
    komowar kuskure;
    }

  22. 31

    ingantaccen aiki Email (fld) {
    var error = ””;
    var tfld = datsa (fld.value); // darajar filin tare da sararin samaniya an datse shi
    var emailFilter = / ^^^]]]]]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/
    var illegalChars = / [(),;: \ ”[]] /;

    idan (fld.value == "Shigar da Adireshin imel ɗin ku") {

    kuskure = “Da fatan za a shigar da adireshin Imel ɗin ku.n”;
    } in kuma idan (! emailFilter.test (tfld)) {// imel gwajin don haruffan doka

    kuskure = “Da fatan za a shigar da adireshin imel mai inganci.n”;
    } in kuma idan (fld.value.match (illegalChars)) {

    kuskure = “Da fatan za a shigar da adireshin imel mai inganci.n”;
    }
    komowar kuskure;
    }

  23. 32

    ingantaccen aiki Email (fld) {
    var error = ””;
    var tfld = datsa (fld.value); // darajar filin tare da sararin samaniya an datse shi
    var emailFilter = / ^^^]]]]]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/
    var illegalChars = / [(),;: \ ”[]] /;

    idan (fld.value == "Shigar da Adireshin imel ɗin ku") {

    kuskure = “Da fatan za a shigar da adireshin Imel ɗin ku.n”;
    } in kuma idan (! emailFilter.test (tfld)) {// imel gwajin don haruffan doka

    kuskure = “Da fatan za a shigar da adireshin imel mai inganci.n”;
    } in kuma idan (fld.value.match (illegalChars)) {

    kuskure = “Da fatan za a shigar da adireshin imel mai inganci.n”;
    }
    komowar kuskure;
    }

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

Me kuke tunani?

Wannan shafin yana amfani da Akismet don rage spam. Koyi yadda aka sarrafa bayanan bayaninka.