#target photoshop
var GUI_TEST = GUI_TEST || {};
(function() {
var layout = "dialog { text: 'GUI TEST', \
edt1: EditText {text: '数字のみ入力可' } \
edt2: EditText {text: '数字とカンマのみ入力可' } \
}";
// 数字のみ入力を許可する
var numericEditKeyboardHandler = function(event) {
var key = event.keyName;
var keyIsOK = ('0' <= key && key <= '9' && !event.shiftKey) ||
key == 'Left' || key == 'Right' ||
key == 'Backspace' || key == 'Delete' ||
key == 'Home' || key == 'End' ||
key == 'Tab' || key == 'Escape';
if (!keyIsOK) {
// keydownイベントを受け付けないようにする
event.preventDefault();
app.beep();
}
};
// 数字とピリオドのみ入力を許可する
var decimalEditKeyboardHandler = function(event) {
var key = event.keyName;
var keyIsOK = ('0' <= key && key <= '9' && !event.shiftKey) ||
key == 'Decimal' || key == 'Period' ||
key == 'Left' || key == 'Right' ||
key == 'Backspace' || key == 'Delete' ||
key == 'Home' || key == 'End' ||
key == 'Tab' || key == 'Escape';
if (!keyIsOK) {
// keydownイベントを受け付けないようにする
event.preventDefault();
app.beep();
}
};
var win = new Window(layout);
win.edt1.addEventListener('keydown', numericEditKeyboardHandler);
win.edt2.addEventListener('keydown', decimalEditKeyboardHandler);
win.show();
}).apply(GUI_TEST);
More than 5 years have passed since last update.
Photoshop | EditTextに数字以外の文字を入力できないようにする
Last updated at Posted at 2018-08-03
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme