cleave.js - more examples

cleave.js - more examples

by Rudchyk

HTML

<script src="https://nosir.github.io/cleave.js/dist/cleave.min.js"></script>
<script src="https://nosir.github.io/cleave.js/dist/cleave-phone.i18n.js"></script>
<div>
    <section>
        <p>Phone Number Prefix/Default Value Bug:</p>
        <input value="8004388898" class="input" />
    </section>   
    <section>
        <p>Phone Number Working with Formatted Value:</p>
        <input value="(800) 555-1234" class="input" />
    </section>   
</div>

CSS

input {
    width: 80%;
    display: block;
    outline: none;
    -webkit-appearance: none;
    border: 1px solid #e6e6e6;
    border-radius: 5px;
    background-color: #fff;
    line-height: 30px;
    vertical-align: middle;
    height: 33px;
    font-size: 14px;
    padding: 0 8px;
}

.input-numeral {
    text-align: right;
}

.right {
    text-align: right;
}

body {
    font-family: sans-serif;
}

p {
    margin: 0;
    padding: 0 0 5px 0;
    font-size: 14px;
    color: #666;
}

section {
    margin-bottom: 10px;
    width: 50%;
    float: left;
}

JavaScript

new Cleave('.input', {
    prefix: '2',
    delimiters: ['-'],
    blocks: [3,3,4]
});