$("#serialform").submit(function(event) {
// If you write return false; in here, then
// the form will not get sent.
// if you write return true; then the form will
// get sent:
event.preventDefault();
// Get the value of the textbox
inputVal = $("#serial").val();
// From @user1515791 answer
// Split it at the dash (-)
console.log(inputVal.indexOf('-'));
if (inputVal.indexOf('-') != 4) {
$("#errmsg").html("Wrong format. Needs four numbers before dash");
return false;
}
var seqs = inputVal.split('-');
var seq1 = seqs[0];
var seq2 = seqs[1];
// seq1 now contains abcd
// and sec2 contains efghij
if (isNaN(parseInt(seq1)) || isNaN(parseInt(seq2))) {
$("#errmsg").html("Got non-numbers in the sequence");
return false;
}
// You can extract the numbers to variables
// like in your question like this
a = seq1[0];
b = seq1[1];
c = seq1[2];
d = seq1[3];
e = seq2[0];
f = seq2[1];
//...
j = seq2[5];
if (a != 1 && a != 2) {
$("#errmsg").html("the first number is not 1 or 2");
return false;
}
f = f * 2;
// ...
return false;
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.