d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help In Javascript > Regexp
Add Reply New Topic New Poll
Member
Posts: 9,746
Joined: Dec 4 2008
Gold: 0.00
May 19 2012 12:20pm
ok so here is my function
Code
function Valider(objet)
   {
     var chaine = document.getElementById(objet.id).value;
     switch(objet.id)
     {
       case "telephone":
         break;
       case "code_postal":
         var code_postal = new RegExp("^[A-Z]\d[A-Z][\s-]?\d[A-Z]\d$");
         if(code_postal.test(chaine) == true)
           alert(true);
         else
           alert(false);
         break;
       case "date":
         break;
       case "nas":
         break;
       case "courriel":
         break;
       case "adr_internet":
         break;
       case "nbr_decimal":
         document.getElementById(objet.id).value = chaine.replace(",",".");
         break;
     }
   }


ok so objet is the input that was sent to the function.

id like to know how to make my case "code_postal" work ... because i have tryed .test and .exec with various way to write it but i cant get it to work ...

btw my RegExp is supose to let pass (cap letter) number (cap letter) space - or nothing number (cap letter) number --> for those who aren't familiar with RegExp
those are supose to be ok:
A9A9A9
A9A 9A9
A9A-9A9
my RegExp is correct and let only pass what it should (tested it on a tester website) but idk how to apply it correctly in my code

any help is really appreciate

This post was edited by djray on May 19 2012 12:31pm
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
May 19 2012 01:27pm
Code
var code_postal = new RegExp(/^[A-Z]\d[A-Z][\s-]?\d[A-Z]\d$/);
Member
Posts: 9,746
Joined: Dec 4 2008
Gold: 0.00
May 21 2012 07:28am
Quote (eagl3s1ght @ 19 May 2012 15:27)
Code
var code_postal = new RegExp(/^[A-Z]\d[A-Z][\s-]?\d[A-Z]\d$/);


thank you man really helpfull
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll