Jump to content
php.lv forumi

Telefona numura validācija


eT`

Recommended Posts

Sveiki,

Kā Jūs realizētu telefona numura validāciju ievades laukā, ja drīkst būt jebkuras pasaules malas telefona numurs.

saglabātu visu valstu telefona numuru uzbūvi un validētu numuru pēc valsts koda vai ir kāds gatavs divritenis?

 

 

Link to comment
Share on other sites

Mums ir apmēram šādi izveidots:

function regexp_this(r_str, r_type)
{
    if(r_type == 'phone')
        var rexp = /^(\+|00)([0-9]){3}( |)(2){1}([0-9]){7}( |)$/;
    else if(r_type == 'postal')
        var rexp = /^(LV\-)([0-9]){4}$/;
    else if(r_type == 'pers_code')
    {
        // datumi kuros ir 01 liidz 28 datums
            var datums0128 = "([012][1-8]|[01]9|[12]0)(0\\d|1[012])\\d{2}";
        // datumi kuros ir 30 liidz 31 datums
            var datums3031 = "3(0(0[13-9]|1[012])|1(0[13578]|1[02]))\\d{2}";
        // datumi kuros ir 29 datums
            var datums29 = "29(02([02468][048]|[13579][26])|(0[13-9]|1[012])\\d{2})";
        
        var rexp = new RegExp("^((" + datums0128 + ")|(" + datums3031 + ")|(" + datums29 + "))-[12]\\d{4}$");
    }
    
    if(rexp)
    {
        return rexp.test(r_str);
    }
    else
        return false;
}


Un pielietojums:

if( !regexp_this(document.form2.mobile.value, 'phone') )
{
    passed = false;
}else{
    passed = true;
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...