Which is best data type for phone number in MySQL and what should Java type mapping for it be?

Strings & VARCHAR. Do not try storing phone numbers as actual numbers. it will ruin the formatting, remove preceding 0s and other undesirable things. You may, if you choose to, restrict user inputs to just numeric values but even in that case, keep your backing persisted data as characters/strings and not numbers. Be aware of … Read more

How to find out if letter is Alphanumeric or Digit in Swift

For Swift 5 see rustylepord’s answer. Update for Swift 3: let letters = CharacterSet.letters let digits = CharacterSet.decimalDigits var letterCount = 0 var digitCount = 0 for uni in phrase.unicodeScalars { if letters.contains(uni) { letterCount += 1 } else if digits.contains(uni) { digitCount += 1 } } (Previous answer for older Swift versions) A possible … Read more

How to allow introducing only digits in jTextField?

Here check this code snippet, that’s how you allow only digits in JTextField, by using DocumentFilter, as the most effeciive way : import java.awt.*; import javax.swing.*; import javax.swing.text.AbstractDocument; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.DocumentFilter; import javax.swing.text.DocumentFilter.FilterBypass; public class InputInteger { private JTextField tField; private MyDocumentFilter documentFilter; private void displayGUI() { JFrame frame = new JFrame(“Input … Read more