Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input condition is wrong #1

Open
tskxz opened this issue Jun 5, 2024 · 1 comment
Open

Input condition is wrong #1

tskxz opened this issue Jun 5, 2024 · 1 comment

Comments

@tskxz
Copy link
Member

tskxz commented Jun 5, 2024

No description provided.

@tskxz
Copy link
Member Author

tskxz commented Jun 5, 2024

The problem is the boolean values are inverse, we need to fix it by changing it return true to return 0 and vice versa return false to return 1

function validateInput() {
    var username = document.getElementById('username').value;
    var regex = /^[a-zA-Z0-9]+$/;
    if (!regex.test(username)) {
        alert('Invalid username. Only alphanumeric characters are allowed.');
         return true;
    }
     return false;
}

To

function validateInput() {
    var username = document.getElementById('username').value;
    var regex = /^[a-zA-Z0-9]+$/;
    if (!regex.test(username)) {
        alert('Invalid username. Only alphanumeric characters are allowed.');
         return 0;
    }
     return 1;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant