Remove literals from jquery input mask after form submit?

edx
edx
48 Points
14 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

Total Answered: 3
Total Marked As Answer: 0
Posted On: 25-Feb-2019 05:51

Share:   fb twitter linkedin
Answers
Alice
Alice
2 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
64 Points
27 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
4 Points
2 Posts
     

Use following JavaScript code

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

Blog

Active User (2)

 Log In to Chat