javascript - Combination of string validity checking using regular expression -


i trying check string validity using regular expressions. string should contain 11 digits. among first 10 digit 1 digit (e.g. digit 0 or 1 or 2 .. or 9) must 2 or 3 time. other remaining digit must 1 time.

how can find answer using regular expressions in javascript or in php? here have created solution in javascript trying same thing using regular expression. not this. kind of solution possible using regular expression ?

function idvalidsteueridentnrgermany(str) {     if(str.length === 11 && (/^\d+$/.test(str) )){          var specialchar = false;         str = str.substring(0, str.length - 1);          for(var = 0; i< str.length; ){             var c = str.charat(i);             var re = new regexp(c, 'g');             var length = (str.match(re)).length;             if((specialchar === false) && (length>1 && length <= 3)){                 specialchar = true;                 str = str.replace(re, '');             }             else if(specialchar === true && length>1  ){                 return false;             }             else if(length > 3)                 return false;             else                 i++;         }         if(specialchar !== false)             return true;     }     else         return false; } 

e.g. input : 12345678910 valid because 1 digit (e.g. 1) occurs here twice , other digit occurs once

e.g. input: 00012345678 00012345670 10203045670 11234567890-> true

e.g: input: 12345678901 111123456789 1ac25bc8970 1110234567.9 10203044567 10203040567 00001234567 -> false


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -