PhoneInputForm.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using SteamAuth;
  2. using System;
  3. using System.Text.RegularExpressions;
  4. using System.Windows.Forms;
  5. namespace Steam_Desktop_Authenticator
  6. {
  7. public partial class PhoneInputForm : Form
  8. {
  9. private SteamGuardAccount Account;
  10. public string PhoneNumber;
  11. public string CountryCode;
  12. public bool Canceled;
  13. public PhoneInputForm(SteamGuardAccount account)
  14. {
  15. this.Account = account;
  16. InitializeComponent();
  17. }
  18. private void btnSubmit_Click(object sender, EventArgs e)
  19. {
  20. this.PhoneNumber = txtPhoneNumber.Text;
  21. this.CountryCode = txtCountryCode.Text;
  22. if (this.PhoneNumber[0] != '+')
  23. {
  24. MessageBox.Show("Phone number must start with + and country code.", "Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
  25. return;
  26. }
  27. this.Close();
  28. }
  29. private void txtPhoneNumber_KeyPress(object sender, KeyPressEventArgs e)
  30. {
  31. // Allow pasting
  32. if (Char.IsControl(e.KeyChar))
  33. return;
  34. // Only allow numbers, spaces, and +
  35. var regex = new Regex(@"[^0-9\s\+]");
  36. if (regex.IsMatch(e.KeyChar.ToString()))
  37. {
  38. e.Handled = true;
  39. }
  40. }
  41. private void txtCountryCode_KeyPress(object sender, KeyPressEventArgs e)
  42. {
  43. // Allow pasting
  44. if (Char.IsControl(e.KeyChar))
  45. return;
  46. // Only allow letters
  47. var regex = new Regex(@"[^a-zA-Z]");
  48. if (regex.IsMatch(e.KeyChar.ToString()))
  49. {
  50. e.Handled = true;
  51. }
  52. }
  53. private void txtCountryCode_Leave(object sender, EventArgs e)
  54. {
  55. // Always uppercase
  56. txtCountryCode.Text = txtCountryCode.Text.ToUpper();
  57. }
  58. private void btnCancel_Click(object sender, EventArgs e)
  59. {
  60. this.Canceled = true;
  61. this.Close();
  62. }
  63. }
  64. }