Skip to content

Commit

Permalink
Merge pull request #124 from kevinakahoshi/zipcode-validation
Browse files Browse the repository at this point in the history
Zipcode validation Regex
  • Loading branch information
vhuynhcao committed Dec 11, 2019
2 parents b06b25a + 286eed0 commit 49e7336
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion client/components/default-page.jsx
Expand Up @@ -9,6 +9,7 @@ class DefaultPage extends React.Component {
super(props);
this.state = {
zipcode: null,
validZip: null,
unmounting: false
};
this.setZip = this.props.setZip;
Expand All @@ -22,8 +23,16 @@ class DefaultPage extends React.Component {

handleSubmit(event) {
event.preventDefault();

const zipcodeRegex = RegExp(/(^\d{5}$)/);
if (zipcodeRegex.test(this.state.zipcode)) {
this.setState({ validZip: true });
this.props.history.push('/activity-filter');
} else {
this.setState({ validZip: false });
}

this.setZip(this.state.zipcode);
this.props.history.push('/activity-filter');
}

render() {
Expand Down

0 comments on commit 49e7336

Please sign in to comment.