Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only letters type #228

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/lib/masks/_base.mask.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/lib/masks/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/lib/masks/only-letters.mask.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type TextInputMaskTypeProp =
| 'cel-phone'
| 'datetime'
| 'custom'
| 'only-letters'

// Option prop of TextInputMask.
export interface TextInputMaskOptionProp {
Expand Down
4 changes: 4 additions & 0 deletions lib/masks/_base.mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default class BaseMask {
removeNotNumbers(text) {
return text.replace(/[^0-9]+/g, '')
}

removeNotLeters(text) {
return text.replace(/\d/g, '')
}

removeWhiteSpaces(text) {
return (text || '').replace(/\s/g, '')
Expand Down
2 changes: 2 additions & 0 deletions lib/masks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import CustomMask from './custom.mask'
import DatetimeMask from './datetime.mask'
import MoneyMask from './money.mask'
import OnlyNumbersMask from './only-numbers.mask'
import OnlyLettersMask from './only-letters.mask'
import ZipCodeMask from './zip-code.mask'
import CreditCardMask from './credit-card.mask'

Expand All @@ -15,5 +16,6 @@ module.exports.CustomMask = CustomMask
module.exports.DatetimeMask = DatetimeMask
module.exports.MoneyMask = MoneyMask
module.exports.OnlyNumbersMask = OnlyNumbersMask
module.exports.OnlyLettersMask = OnlyLettersMask
module.exports.ZipCodeMask = ZipCodeMask
module.exports.CreditCardMask = CreditCardMask
23 changes: 23 additions & 0 deletions lib/masks/only-letters.mask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import BaseMask from './_base.mask'

export default class OnlyLettersMask extends BaseMask {
static getType() {
return 'only-letters'
}

getValue(value, settings) {
return this.removeNotLetters(String(value))
}

getRawValue(maskedValue, settings) {
return super.removeNotLetters(String(maskedValue))
}

validate(value, settings) {
return true
}

getMask(value, settings) {
return ''
}
}