문제

This code shows error message when there is no value entered. How do i create a coding to have an minimum input of 8 characters?

For Null value:

if ($("shipping_tel")) {
            if ($("shipping_tel").value === "") { 
                ErrorMsg += " - Shipping Address: Phone Number\n";
                $("shipping_tel_label").className = 'hilight';
            } else {
                $("shipping_tel_label").className = 'lolight';      
            }
        }

For minimum input value:

if ($("shipping_tel")) {
            if ($("shipping_tel").value < 8) { 
                ErrorMsg += " - Shipping Address: Phone Number\n";
                $("shipping_tel_label").className = 'hilight';
            } else {
                $("shipping_tel_label").className = 'lolight';      
            }
        }

but this does not work. Any idea?

도움이 되었습니까?

해결책

Try this

str = $("shipping_tel").value;
//This regular expression checks the string.
var patt=/[0-9]{8,}/g;  //atleast 8 nums long.
if(patt.exec(str)!=str){
    ErrorMsg = " - Shipping Address: Phone Number\n";
    $("shipping_tel_label").className = 'hilight';
}else{
    $("shipping_tel_label").className = 'lolight';
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top