technojam / technojam-frontend

This is the repository for TechnoJam's website frontend, for work please work on Development 1.0. Please do git pull before giving a pull request.
https://technojam--web.herokuapp.com/
MIT License
33 stars 97 forks source link

Data Validation #233

Closed lakshya-20 closed 4 years ago

lakshya-20 commented 4 years ago

Add input validation of the data received while creating a new account to ensure only properly formed data is entering the workflow.

Entries to be verified:

jz543fm commented 4 years ago

Working on this

jz543fm commented 4 years ago

File in /src/TopMenu.js

Updated and added: Check on name lenght and then test on String email via RegEx expression

const handleRegister = e => {
    e.preventDefault();
    if(name.length <= 3){
        setAlert('Name should not be of length less than 3.', 'danger');
    }
    const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    re.test(String(email).toLocaleLowerCase);
    if(re.test(email) == false){
        setAlert('Not valid email address!', 'danger');
    }

    if (name === '' || email === '' || password === '') {
        setAlert('Please fill in all fields', 'danger');
    } else {
        console.log('register called');
        showLoading({ data: true });
        register({
            name,
            email,
            password
        });
    }
};
jz543fm commented 4 years ago

Can it be considered as fix for this issue?

illegalcall commented 4 years ago

I'll be happy to contribute.

lakshya-20 commented 4 years ago

Can it be considered as fix for this issue?

Yes, it's working fine! Thanks