Skip to content

Instantly share code, notes, and snippets.

@tuncatunc
Last active December 1, 2017 11:31
Show Gist options
  • Save tuncatunc/c5ff0b8adfaf0a86d06720669fb220b1 to your computer and use it in GitHub Desktop.
Save tuncatunc/c5ff0b8adfaf0a86d06720669fb220b1 to your computer and use it in GitHub Desktop.
ipMasking with redux-form Field component normalize
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