Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to ensure that edittext entries contain no letters but only numbers

Community Expert ,
Aug 27, 2008 Aug 27, 2008
Im trying to set up a dialog that contains an edittext-field to enter an intended width and some radiobuttons that represent various saving-locations for a copy of an image.
But I foresee certain problems so my questions are:
Is there a way to ensure that no letters but only numbers are entered in an edittext-field?
And is there a way to remove Umlauts and other problematic characters from the filename prior to saving the copy?

I know that probably the info is out there somewhere, but Id certainly appreciate any help.
TOPICS
Actions and scripting
838
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Aug 27, 2008 Aug 27, 2008
Which scripting language are you using?

If it's JS, you can use this:
var patt1 = new RegExp(/\D/);
if (patt1.test(str)) {} // It's not a number
else {} //It is a number

But be advised that this will work with numbers ONLY, so periods, commas, spaces and the like will not be accepted.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2008 Aug 27, 2008
How embarrassing, I forgot to mention Im working with JavaScript.
First of thanks, but ... could one allow for commas after all?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 28, 2008 Aug 28, 2008
numberKeystrokeFilter = function() {
if (this.text.match(/[^\-\.\d]/)) {
this.text = this.text.replace(/[^\-\.\d]/g, '');
}
};
numericKeystrokeFilter = function() {
if (this.text.match(/[^\d]/)) {
this.text = this.text.replace(/[^\d]/g, '');
}
};


edittext.onChange = numberKeystrokeFilter;
edittext.onChange = numericKeystrokeFilter;


The first thing matches floats and negative floats. Kinda.
The second match simple integers.

Tweak 'em while ya got em.

-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 28, 2008 Aug 28, 2008
Thanks, xbytor!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 28, 2008 Aug 28, 2008
Here are 2 of the Regular Expressions I use to validate numeric entry

Strict use of commas (commas are optional, but must be used consistently)
^\-?([0-9]{1,3}(\,[0-9]{3})*|[0-9]*)(\.[0-9]+)?$

Semi-strict use of commas (commas are optional, as long as they are in the correct place)
^\-?[0-9]*(\,?[0-9]{3})*(\.[0-9]+)?$

The first one will allow
10,000,000,000,000,000
10000000000000000

The second one will also allow
10,000000,000,000000

I believe I should have another regex that I use for validation during entry, but I can't seem to locate it right now.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 28, 2008 Aug 28, 2008
LATEST
Thanks!
Thats a lot of ways You offered for doing that!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines