Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  90] [ 3]  / answers: 1 / hits: 21831  / 13 Years ago, fri, october 7, 2011, 12:00:00

I have a textfield and the user enters the SSN number. While entering itself it should format. Like On the change of the textField... it should format 999-999-999 in this way on the display itself.


More From » javascript

 Answers
16
<input id=ssn/>

<script type=text/javascript>
$('#ssn').keyup(function() {
var val = this.value.replace(/D/g, '');
val = val.replace(/^(d{3})/, '$1-');
val = val.replace(/-(d{2})/, '-$1-');
val = val.replace(/(d)-(d{4}).*/, '$1-$2');
this.value = val;
});
</script>

[#89743] Wednesday, October 5, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shianncaylinc

Total Points: 502
Total Questions: 80
Total Answers: 105

Location: Botswana
Member since Sat, Jan 7, 2023
1 Year ago
;