Remove literals from jquery input mask after form submit?

edx
edx
506 Points
24 Posts

I'm using jquery.mask to mask phone number input field:

<input 
class="custom-phone-field"
type="tel"
placeholder="(XX) - XXXX - XXXX"
data-mask="(00) 0000 - 0000" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.15/jquery.mask.min.js"></script>

 

It's mask fine but when form submitting to server the value is coming with mask value. I want to get phone number without masking.
Example :

Mask input: (11) 1111 - 1111
I want on server side: 1111111111

Views: 18137
Total Answered: 3
Total Marked As Answer: 1
Posted On: 25-Feb-2019 05:51

Share:   fb twitter linkedin
Answers
Alice
Alice
32 Points
1 Posts
         

Use unmask:

<input 
id="txtPhone"
class="custom-phone-field"
type="tel"
placeholder="(XX) - XXXX - XXXX"
data-mask="(00) 0000 - 0000" />
$("#txtPhone").unmask();
Posted On: 28-Feb-2019 08:00
beginer
beginer
1544 Points
52 Posts
         

Suppose myForm is form id then following will be javascript code

$("#myForm").submit(function() {
  $("#txtPhone").unmask();
});
Posted On: 28-Feb-2019 08:21
kd
kd
12 Points
1 Posts
         

Use following JavaScript code

$("#txtPhone").inputmask(
  {removeMaskOnSubmit: true}
);
Posted On: 28-Feb-2019 22:28
 Log In to Chat