Despite reading several tutorials on regular expressions, I am still struggling to create the exact expression I need.
I have an onblur function that performs the following actions...
var x = $("#outputpathid").val();
var testwhitespace = new RegExp(/\s/g);
var testdoublequotes = new RegExp(/^\"|\"$/);
if (testwhitespace.test(x) && !testdoublequotes.test(x)) {
$("#outputPathDivWhitespace").dialog({
title: 'Output Path contains whitespace. Click the \'Close\' button to add quotes.',
width: 500,
modal: true,
resizable: false,
buttons: {
'Close': function() {
$("#outputpathid").val('"'+x+'"');
$(this).dialog('close');
}
}
});
}
...I want this function to determine if the input field string, x, contains any whitespace characters. If it does and there are no quotes present, then surrounding the entire string with quotes should be done. However, this solution fails when the string starts or ends with a quote.
I am searching for the proper 'and' operator to replace the pipe character in the testdoublequotes variable. I have tried using the '?' but it doesn't seem to work as expected.
If anyone could offer some assistance, please provide a detailed explanation of your solution so that I can grasp the concept. Thank you!