I don't have previous experience working with regex and that's why I need your help.
I have 3 different web services which I'm using to grab data via live search. Here is the logic of my statement which I'm trying to implement.
if(carName is entered) {
getCarName.php?text=blablabla
} elseif (carModel is entered) {
getCarModel.php?text=blablabla
} elseif (carNumer is entered) {
getCarNumber.php?text=1337
}
The idea is if carName is entered it could be a simple string like Pontiac Firebird 2002, then carModel can be OHC inline-6 and a single-barrel carburetor. carName and carModel may contain characters and numbers. carNumber can have numbers-only value like 194378.
I've started evaluation regexr.com website, but still didn't came up with a possible solution to my problem.
I want to have 1 input field (search field). I have different 3 web services. I have a working live search for 1 web service (carName). It's working fine, but I want to make a regex statement to find out when in the input search field is entered carName or carModel or even carNumber. How I can do it?
As an example, here is a code snippet for my live search for carName web service:
$('#search').keyup(function() {
var searchField = $('#search').val();
var $update = $('#update');
$.get("getCarName.php?text=" + searchField, function(data) {
$update.empty();
var vals = jQuery.parseJSON(data);
if($.isArray(vals['Car'])) {
$.each(vals['car'], function(k,v){
$update.append("<li value='"+v['id']+"'><a href='#'>" + v['car_name'] + "</a></li>");
});
} else {
$update.append("<li value='"+vals['car']['id']+"'><a href='#'>" + vals['car']['car_name'] + "</a></li>");
}
});
});
Based on a code above, I want to create an if/else statement to figure it what which web service it should use based on the input string.
According to the regexr.com carName and carModel can be achieved from:
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
And carNumber from:
0123456789
Buy how I can create a If/Else condition according to this?
Can please anyone help me with that?
<input type="number" ...>:)