Validators within a denied JavaScript condition

1

I have a problem with a condition that I perform in javascript, I send to call id's with a denied condition, if all the inputs are different to empty, then I save the data in the database, however there are some cases in which I apply regular expressions, so the condition in some id no longer have to be denied, if not equal, but I do it and it does not store the data, I would like to know a way to do it, thanks.

Javascript

                case "UpdatePerfil":
                    {
                        if (document.getElementById('Perfil_Nombre').value != "" &&
                            document.getElementById('Perfil_ApellidoPaterno').value != "" &&
                            document.getElementById('Perfil_FechaNacimiento').value != "" &&
                            document.getElementById('ddl_Perfil_Sexo').value != "" &&
                            document.getElementById('ddl_Perfil_Pais').value != "" &&
                            document.getElementById('ddl_Perfil_Estado').value != "" &&     

            document.getElementById('Perfil_RFC').value != "" &&
                document.getElementById('Perfil_RFC').value == /^([a-zA-

Z&Ññ]{3}|[a-zA-Z][aeiouAEIOU][a-zA-Z]{2})\d{2}((01|03|05|07|08|10|12)(0[1-9]|[12]\d|3

[01])|02(0[1-9]|[12]\d)|(04|06|09|11)(0[1-9]|[12]\d|30))([a-zA-Z0-9]{2}[0-9Aa])?$/) {
    
asked by Guillermo Navarro 01.09.2016 в 06:30
source

2 answers

5

Regular expressions are compared to different methods but not with == or != . In your case you could use this:

var exp = /tuexpresionregular/;
if (exp.test(document.getElementById("tuid"))){}

Here you have more information.

    
answered by 01.09.2016 / 07:10
source
0

As well commented above, you have to apply the test function of the regular expression to check whether it is fulfilled or not, this function returns true / false. Seeing the size of the if, it would not be a bad idea to take it to a function for future modifications.

var regExp = /^([a-zA-Z&Ññ]{3}|[a-zA-Z][aeiouAEIOU][a-zA-Z]{2})\d{2}((01|03|05|07|08|10|12)(0[1-9]|[12]\d|3[01])|02(0[1-9]|[12]\d)|(04|06|09|11)(0[1-9]|[12]\d|30))([a-zA-Z0-9]{2}[0-9Aa])?$/;

...    

case "UpdatePerfil":
    if (document.getElementById('Perfil_Nombre').value &&
        document.getElementById('Perfil_ApellidoPaterno').value &&
        document.getElementById('Perfil_FechaNacimiento').value &&
        document.getElementById('ddl_Perfil_Sexo').value &&
        document.getElementById('ddl_Perfil_Pais').value &&
        document.getElementById('ddl_Perfil_Estado').value &&     
        document.getElementById('Perfil_RFC').value &&
        regExp.test(document.getElementById('Perfil_RFC').value)) {
    
answered by 01.09.2016 в 10:22