Skip to content

Instantly share code, notes, and snippets.

@ShekharReddy4
Created November 10, 2016 18:41
Show Gist options
  • Save ShekharReddy4/7138e578ab4884ffc0d91fad97693cac to your computer and use it in GitHub Desktop.
Save ShekharReddy4/7138e578ab4884ffc0d91fad97693cac to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$("#sub").click(function(){
var inputtedRollNumber = $( "#roll" ).val();
console.log(inputtedRollNumber);
// Match only numbers
var rollNumberRegex = /13bd1a05(?:[0-5][0-9]|60)/i;
// If the roll number doesn't match the regex
if ( !rollNumberRegex.test( inputtedRollNumber ) ) {
alert("please fill with a valid roll number");
// Usually show some kind of error message here//
// Prevent the form from submitting
event.preventDefault();
} else {
// Run $.ajax() here
$.ajax({url: "result", success: function(result){
console.log("success");
}});
}});
});
</script>
<form id="details">
<header>Details</header>
<label>Roll Number <span>*</span></label>
<input type="text" id="roll" required/>
<div class="help">Must be 10 characters</div>
<button type="button" id="sub">Submit</button>
</form>
<a href="https://github.com/shekharreddy4/results"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment