Skip to content

Instantly share code, notes, and snippets.

@awhitty
Created January 29, 2014 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awhitty/8683206 to your computer and use it in GitHub Desktop.
Save awhitty/8683206 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Email Form</title>
</head>
<body>
<form action="">
<input type="text" placeholder="Email">
<input type="submit">
</form>
<!-- Firebase.js -->
<script type='text/javascript' src='https://cdn.firebase.com/js/client/1.0.2/firebase.js'></script>
<!-- jQuery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
var fb = new Firebase(PUT_YOUR_FIREBASE_URL_HERE);
$('form').on('submit', function() {
var email_address = $('input').val()
if (validateEmail(email_address)) {
fb.child('emails').push(email_address)
};
})
function validateEmail(email) {
var 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,}))$/;
return re.test(email);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment