-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for different phone number countries
- Loading branch information
1 parent
82adc8d
commit 6a3108c
Showing
6 changed files
with
2,134 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using SteamAuth; | ||
using System; | ||
using System.Text.RegularExpressions; | ||
using System.Windows.Forms; | ||
|
||
namespace Steam_Desktop_Authenticator | ||
{ | ||
public partial class PhoneInputForm : Form | ||
{ | ||
private SteamGuardAccount Account; | ||
public string PhoneNumber; | ||
public string CountryCode; | ||
public bool Canceled; | ||
|
||
public PhoneInputForm(SteamGuardAccount account) | ||
{ | ||
this.Account = account; | ||
InitializeComponent(); | ||
} | ||
|
||
private void btnSubmit_Click(object sender, EventArgs e) | ||
{ | ||
this.PhoneNumber = txtPhoneNumber.Text; | ||
this.CountryCode = txtCountryCode.Text; | ||
|
||
if (this.PhoneNumber[0] != '+') | ||
{ | ||
MessageBox.Show("Phone number must start with + and country code.", "Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
return; | ||
} | ||
|
||
this.Close(); | ||
} | ||
|
||
private void txtPhoneNumber_KeyPress(object sender, KeyPressEventArgs e) | ||
{ | ||
// Allow pasting | ||
if (Char.IsControl(e.KeyChar)) | ||
return; | ||
|
||
// Only allow numbers, spaces, and + | ||
var regex = new Regex(@"[^0-9\s\+]"); | ||
if (regex.IsMatch(e.KeyChar.ToString())) | ||
{ | ||
e.Handled = true; | ||
} | ||
} | ||
|
||
private void txtCountryCode_KeyPress(object sender, KeyPressEventArgs e) | ||
{ | ||
// Allow pasting | ||
if (Char.IsControl(e.KeyChar)) | ||
return; | ||
|
||
// Only allow letters | ||
var regex = new Regex(@"[^a-zA-Z]"); | ||
if (regex.IsMatch(e.KeyChar.ToString())) | ||
{ | ||
e.Handled = true; | ||
} | ||
} | ||
|
||
private void txtCountryCode_Leave(object sender, EventArgs e) | ||
{ | ||
// Always uppercase | ||
txtCountryCode.Text = txtCountryCode.Text.ToUpper(); | ||
} | ||
|
||
private void btnCancel_Click(object sender, EventArgs e) | ||
{ | ||
this.Canceled = true; | ||
this.Close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.