Skip to content

Commit 4dac331

Browse files
committed
Code fix for Phone field accepting non numeric characters
1 parent 2518468 commit 4dac331

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/Modules/SimplCommerce.Module.Checkouts/Areas/Checkouts/ViewModels/ShippingAddressVm.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -12,6 +13,9 @@ public class ShippingAddressVm
1213

1314
public string ContactName { get; set; }
1415

16+
[Required(ErrorMessage = "Phone number is required")]
17+
[Phone(ErrorMessage = "Please enter a valid phone number")]
18+
[StringLength(20, MinimumLength = 10, ErrorMessage = "Phone number must be between 10 and 20 characters")]
1519
public string Phone { get; set; }
1620

1721
public string AddressLine1 { get; set; }

src/Modules/SimplCommerce.Module.Checkouts/Areas/Checkouts/Views/Checkout/Shipping.cshtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
<div class="form-group row">
8484
<label class="col-sm-4 col-form-label">@Localizer["Phone"]</label>
8585
<div class="col-sm-8">
86-
<input asp-for="NewAddressForm.Phone" type="text" class="form-control">
86+
<input asp-for="NewAddressForm.Phone" type="tel"inputmode="numeric" class="form-control"
87+
oninput="this.value = this.value.split('').filter(function(c){return c >= '0' && c <= '9';}).join('');">
8788
</div>
8889
</div>
8990
</div>
@@ -174,7 +175,8 @@
174175
<div class="form-group row">
175176
<label class="col-sm-4 col-form-label">@Localizer["Phone"]</label>
176177
<div class="col-sm-8">
177-
<input asp-for="NewBillingAddressForm.Phone" type="text" class="form-control">
178+
<input asp-for="NewBillingAddressForm.Phone" type="tel" inputmode="numeric" class="form-control"
179+
oninput="this.value = this.value.split('').filter(function(c){return c >= '0' && c <= '9';}).join('');">
178180
</div>
179181
</div>
180182
</div>

0 commit comments

Comments
 (0)