validation - Javascript, check for identical characters -
i got make script checking input box (password) same characters occuring twice. should used alongside regex validation (that's working).
succeed know need use (for?) loop somehow, checks if 1 character appear twice. kind of odd thing ask for. know. i'm not entirely sure conditions function. if have suggestions around how made, great. example: "abad12" - pass, whilst "abac12" return false. in advance.
function checkform(form) { var re = /^\w{6,10}$/; if(!re.test(form.pwd1.value)) { alert("error: password has in-between 6-10 characters!"); form.inputfield.focus(); return false; } }
above goes example of script i'd combine (among more regex validations).
that's how this:
var str = "abad12", valid = str.split("").filter(function(e, i, a) { return a.indexof(e) !== i; }).length === 0; if (!valid) { // ... }
but note array filter()
method not available in old browsers, check browser compatibility page in advance.
Comments
Post a Comment