Last active
December 1, 2017 11:31
-
-
Save tuncatunc/c5ff0b8adfaf0a86d06720669fb220b1 to your computer and use it in GitHub Desktop.
ipMasking with redux-form Field component normalize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ipNormalize = (value, prev, values, prevValues) => { | |
let length = value.length | |
let index = value.lastIndexOf('.') + 1 | |
let noOfDots = value.split('.').length -1 | |
let updatedVal = '' | |
if (length !== index && noOfDots < 3 && prev.length < length && (length - index) % 3 == 0) { | |
updatedVal = value + '.' | |
} | |
else if (noOfDots > 3 || length - index > 3){ | |
let newString = value.substring(0, length - 1) | |
updatedVal = newString | |
} | |
else { | |
updatedVal = value | |
} | |
return updatedVal | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment