Skip to content

Commit

Permalink
Merge pull request #51 from hargata/Hargata.international.numbers
Browse files Browse the repository at this point in the history
added support for international number formats.
  • Loading branch information
hargata authored Jan 10, 2024
2 parents 7e4f580 + 7bfbb49 commit a467ba0
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Views/Vehicle/_CollisionRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<label for="collisionRecordDescription">Description</label>
<input type="text" id="collisionRecordDescription" class="form-control" placeholder="Description of item(s) repaired(i.e. Alternator)" value="@Model.Description">
<label for="collisionRecordCost">Cost</label>
<input type="number" id="collisionRecordCost" class="form-control" placeholder="Cost of the repair" value="@(isNew ? "" : Model.Cost)">
<input type="text" id="collisionRecordCost" class="form-control" placeholder="Cost of the repair" value="@(isNew ? "" : Model.Cost)">
</div>
<div class="col-md-6 col-12">
<label for="collisionRecordNotes">Notes(optional)</label>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_GasModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<label class="form-check-label" for="gasIsFillToFull">Is Filled To Full</label>
</div>
<label for="GasRecordCost">Cost</label>
<input type="number" id="gasRecordCost" class="form-control" placeholder="Cost of gas refueled" value="@(isNew ? "" : Model.GasRecord.Cost)">
<input type="text" id="gasRecordCost" class="form-control" placeholder="Cost of gas refueled" value="@(isNew ? "" : Model.GasRecord.Cost)">
</div>
<div class="col-md-6 col-12">
@if (Model.GasRecord.Files.Any())
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_ServiceRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<label for="serviceRecordDescription">Description</label>
<input type="text" id="serviceRecordDescription" class="form-control" placeholder="Description of item(s) serviced(i.e. Oil Change)" value="@Model.Description">
<label for="serviceRecordCost">Cost</label>
<input type="number" id="serviceRecordCost" class="form-control" placeholder="Cost of the service" value="@(isNew ? "" : Model.Cost)">
<input type="text" id="serviceRecordCost" class="form-control" placeholder="Cost of the service" value="@(isNew ? "" : Model.Cost)">
</div>
<div class="col-md-6 col-12">
<label for="serviceRecordNotes">Notes(optional)</label>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_TaxRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<label for="taxRecordDescription">Description</label>
<input type="text" id="taxRecordDescription" class="form-control" placeholder="Description of tax paid(i.e. Registration)" value="@Model.Description">
<label for="taxRecordCost">Cost</label>
<input type="number" id="taxRecordCost" class="form-control" placeholder="Cost of tax paid" value="@(isNew? "" : Model.Cost)">
<input type="text" id="taxRecordCost" class="form-control" placeholder="Cost of tax paid" value="@(isNew? "" : Model.Cost)">
</div>
<div class="col-md-6 col-12">
<label for="taxRecordNotes">Notes(optional)</label>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_UpgradeRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<label for="upgradeRecordDescription">Description</label>
<input type="text" id="upgradeRecordDescription" class="form-control" placeholder="Description of item(s) upgraded/modded" value="@Model.Description">
<label for="upgradeRecordCost">Cost</label>
<input type="number" id="upgradeRecordCost" class="form-control" placeholder="Cost of the upgrade/mods" value="@(isNew ? "" : Model.Cost)">
<input type="text" id="upgradeRecordCost" class="form-control" placeholder="Cost of the upgrade/mods" value="@(isNew ? "" : Model.Cost)">
</div>
<div class="col-md-6 col-12">
<label for="upgradeRecordNotes">Notes(optional)</label>
Expand Down
2 changes: 1 addition & 1 deletion wwwroot/js/collisionrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion wwwroot/js/gasrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion wwwroot/js/servicerecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions wwwroot/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
2 changes: 1 addition & 1 deletion wwwroot/js/taxrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 14 additions & 14 deletions wwwroot/js/upgraderecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit a467ba0

Please sign in to comment.