diff --git a/Views/Vehicle/_CollisionRecordModal.cshtml b/Views/Vehicle/_CollisionRecordModal.cshtml index a61e3c86..69536725 100644 --- a/Views/Vehicle/_CollisionRecordModal.cshtml +++ b/Views/Vehicle/_CollisionRecordModal.cshtml @@ -22,7 +22,7 @@ - +
diff --git a/Views/Vehicle/_GasModal.cshtml b/Views/Vehicle/_GasModal.cshtml index 593dcc10..86d8f0cb 100644 --- a/Views/Vehicle/_GasModal.cshtml +++ b/Views/Vehicle/_GasModal.cshtml @@ -51,7 +51,7 @@
- +
@if (Model.GasRecord.Files.Any()) diff --git a/Views/Vehicle/_ServiceRecordModal.cshtml b/Views/Vehicle/_ServiceRecordModal.cshtml index c37913a6..8edbd197 100644 --- a/Views/Vehicle/_ServiceRecordModal.cshtml +++ b/Views/Vehicle/_ServiceRecordModal.cshtml @@ -22,7 +22,7 @@ - +
diff --git a/Views/Vehicle/_TaxRecordModal.cshtml b/Views/Vehicle/_TaxRecordModal.cshtml index 0c18eca8..61abe782 100644 --- a/Views/Vehicle/_TaxRecordModal.cshtml +++ b/Views/Vehicle/_TaxRecordModal.cshtml @@ -20,7 +20,7 @@ - +
diff --git a/Views/Vehicle/_UpgradeRecordModal.cshtml b/Views/Vehicle/_UpgradeRecordModal.cshtml index ee8e36b2..a8b0e8ec 100644 --- a/Views/Vehicle/_UpgradeRecordModal.cshtml +++ b/Views/Vehicle/_UpgradeRecordModal.cshtml @@ -22,7 +22,7 @@ - +
diff --git a/wwwroot/js/collisionrecord.js b/wwwroot/js/collisionrecord.js index 4b2a024d..fd1dc722 100644 --- a/wwwroot/js/collisionrecord.js +++ b/wwwroot/js/collisionrecord.js @@ -103,7 +103,7 @@ function getAndValidateCollisionRecordValues() { } else { $("#collisionRecordDescription").removeClass("is-invalid"); } - if (collisionCost.trim() == '') { + if (collisionCost.trim() == '' || !isValidMoney(collisionCost)) { hasError = true; $("#collisionRecordCost").addClass("is-invalid"); } else { diff --git a/wwwroot/js/gasrecord.js b/wwwroot/js/gasrecord.js index 9e61b87a..f91bcf2f 100644 --- a/wwwroot/js/gasrecord.js +++ b/wwwroot/js/gasrecord.js @@ -99,7 +99,7 @@ function getAndValidateGasRecordValues() { } else { $("#gasRecordGallons").removeClass("is-invalid"); } - if (gasCost.trim() == '') { + if (gasCost.trim() == '' || !isValidMoney(gasCost)) { hasError = true; $("#gasRecordCost").addClass("is-invalid"); } else { diff --git a/wwwroot/js/servicerecord.js b/wwwroot/js/servicerecord.js index b538deb9..7b8c7d6c 100644 --- a/wwwroot/js/servicerecord.js +++ b/wwwroot/js/servicerecord.js @@ -103,7 +103,7 @@ function getAndValidateServiceRecordValues() { } else { $("#serviceRecordDescription").removeClass("is-invalid"); } - if (serviceCost.trim() == '') { + if (serviceCost.trim() == '' || !isValidMoney(serviceCost)) { hasError = true; $("#serviceRecordCost").addClass("is-invalid"); } else { diff --git a/wwwroot/js/shared.js b/wwwroot/js/shared.js index fa1f8fc7..eae6be6a 100644 --- a/wwwroot/js/shared.js +++ b/wwwroot/js/shared.js @@ -110,4 +110,11 @@ function uploadFileAsync(event) { } } }); +} +function isValidMoney(input) { + const euRegex = /^\$?(?=\(.*\)|[^()]*$)\(?\d{1,3}(\.?\d{3})?(,\d{1,3}?)?\)?$/; + const usRegex = /^\$?(?=\(.*\)|[^()]*$)\(?\d{1,3}(,?\d{3})?(\.\d{1,3}?)?\)?$/; + console.log(euRegex.test(input)); + console.log(usRegex.test(input)); + return (euRegex.test(input) || usRegex.test(input)); } \ No newline at end of file diff --git a/wwwroot/js/taxrecord.js b/wwwroot/js/taxrecord.js index 258ce4ae..313fbaba 100644 --- a/wwwroot/js/taxrecord.js +++ b/wwwroot/js/taxrecord.js @@ -96,7 +96,7 @@ function getAndValidateTaxRecordValues() { } else { $("#taxRecordDescription").removeClass("is-invalid"); } - if (taxCost.trim() == '') { + if (taxCost.trim() == '' || !isValidMoney(taxCost)) { hasError = true; $("#taxRecordCost").addClass("is-invalid"); } else { diff --git a/wwwroot/js/upgraderecord.js b/wwwroot/js/upgraderecord.js index aee9ef49..34f87b6f 100644 --- a/wwwroot/js/upgraderecord.js +++ b/wwwroot/js/upgraderecord.js @@ -75,35 +75,35 @@ function saveUpgradeRecordToVehicle(isEdit) { }) } function getAndValidateUpgradeRecordValues() { - var serviceDate = $("#upgradeRecordDate").val(); - var serviceMileage = $("#upgradeRecordMileage").val(); - var serviceDescription = $("#upgradeRecordDescription").val(); - var serviceCost = $("#upgradeRecordCost").val(); - var serviceNotes = $("#upgradeRecordNotes").val(); + var upgradeDate = $("#upgradeRecordDate").val(); + var upgradeMileage = $("#upgradeRecordMileage").val(); + var upgradeDescription = $("#upgradeRecordDescription").val(); + var upgradeCost = $("#upgradeRecordCost").val(); + var upgradeNotes = $("#upgradeRecordNotes").val(); var vehicleId = GetVehicleId().vehicleId; var upgradeRecordId = getUpgradeRecordModelData().id; var addReminderRecord = $("#addReminderCheck").is(":checked"); //validation var hasError = false; - if (serviceDate.trim() == '') { //eliminates whitespace. + if (upgradeDate.trim() == '') { //eliminates whitespace. hasError = true; $("#upgradeRecordDate").addClass("is-invalid"); } else { $("#upgradeRecordDate").removeClass("is-invalid"); } - if (serviceMileage.trim() == '' || parseInt(serviceMileage) < 0) { + if (upgradeMileage.trim() == '' || parseInt(upgradeMileage) < 0) { hasError = true; $("#upgradeRecordMileage").addClass("is-invalid"); } else { $("#upgradeRecordMileage").removeClass("is-invalid"); } - if (serviceDescription.trim() == '') { + if (upgradeDescription.trim() == '') { hasError = true; $("#upgradeRecordDescription").addClass("is-invalid"); } else { $("#upgradeRecordDescription").removeClass("is-invalid"); } - if (serviceCost.trim() == '') { + if (upgradeCost.trim() == '' || !isValidMoney(upgradeCost)) { hasError = true; $("#upgradeRecordCost").addClass("is-invalid"); } else { @@ -113,11 +113,11 @@ function getAndValidateUpgradeRecordValues() { id: upgradeRecordId, hasError: hasError, vehicleId: vehicleId, - date: serviceDate, - mileage: serviceMileage, - description: serviceDescription, - cost: serviceCost, - notes: serviceNotes, + date: upgradeDate, + mileage: upgradeMileage, + description: upgradeDescription, + cost: upgradeCost, + notes: upgradeNotes, files: uploadedFiles, addReminderRecord: addReminderRecord }