Cov txheej txheem:

Yuav ua li cas koj xyuas seb ib txoj hlua yog alphanumeric hauv Javascript?
Yuav ua li cas koj xyuas seb ib txoj hlua yog alphanumeric hauv Javascript?

Video: Yuav ua li cas koj xyuas seb ib txoj hlua yog alphanumeric hauv Javascript?

Video: Yuav ua li cas koj xyuas seb ib txoj hlua yog alphanumeric hauv Javascript?
Video: Qhia saib yus tus hlub lub xov tooj seb nws kov txog dab tsi thaum yus nyob deb 2024, Tej zaum
Anonim

Tshawb xyuas cov lej thiab cov ntawv

  1. Javascript ua haujlwm rau kuaj yog tias ib daim teb input muaj cov ntawv thiab cov lej nkaus xwb // Function to kuaj cov tsiaj ntawv thiab cov lej ua haujlwm alphanumeric (inputtxt) { var letterNumber = /^[0-9a-zA-Z]+$/; yog ((inputtxt.value.match(letterNumber)) {rov qab muaj tseeb; } else { ceeb toom("message"); rov qab tsis tseeb; } }
  2. Flowchart:
  3. HTML Code <!

Tsuas yog li ntawd, koj yuav kuaj xyuas li cas yog tias tsab ntawv nyob hauv txoj hlua JavaScript?

Pre-ES6, txoj hauv kev zoo rau kuaj yog tias a txoj hlua muaj ib tug substring yog siv indexOf, uas yog a txoj hlua txoj kev uas rov -1 yog tus txoj hlua tsis muaj substring. Yog cov substring pom, nws rov qab qhov Performance index ntawm tus cwj pwm uas pib lub txoj hlua.

Kuj Paub, koj yuav kuaj xyuas li cas yog tias cov tswv yim yog tus lej hauv JavaScript? Hauv JavaScript, muaj ob txoj hauv kev los xyuas seb qhov sib txawv yog tus lej:

  1. isNaN() - Stands rau "Tsis yog Tus Naj Npawb", yog tias qhov sib txawv tsis yog tus lej, nws rov qab muaj tseeb, lwm qhov rov qab tsis tseeb.
  2. typeof – Yog tias qhov sib txawv yog tus lej, nws yuav rov qab ib txoj hlua hu ua "tus lej".

Hais txog qhov no, alphanumeric validation yog dab tsi?

Alphanumeric validation txhais tau hais tias ib daim teb hauv daim ntawv tuaj yeem lees txais cov lej lossis cov cim uas tsis yog yuav txais. Hauv hom no kev lees paub Koj tuaj yeem nkag tau tsuas yog cov cim hauv lub npe, tus lej hauv daim teb sau npe, lossis kev sib xyaw ntawm tus lej thiab cov cim hauv daim npav ID tab sis tsis muaj lub cim tshwj xeeb.

Dab tsi yog qhov piv txwv alphanumeric?

Siv alphanumeric hauv ib kab lus. npe. Lub ntsiab txhais ntawm alphanumeric yog ib yam uas muaj cov tsiaj ntawv thiab tus lej. Ib lo lus zais uas yuav tsum tau muaj ob tus tsiaj ntawv thiab tus lej yog ib qho piv txwv ntawm ib alphanumeric tus password. Lub computer keyboard yog ib qho piv txwv ntawm ib alphanumeric keyboard.

Pom zoo: