Last active
April 28, 2021 21:41
-
-
Save a5ync/20723ea8473936146d27ce5fb7354337 to your computer and use it in GitHub Desktop.
Formatowanie textu
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace WindowsFormsApp2 | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
public static class FormInputHelper | |
{ | |
public static char[] trimmers = { '-' }; | |
public static string FilterName(string input) | |
{ | |
input = input | |
.Trim() | |
.Trim(trimmers) | |
.Trim('-'); | |
input = FilterForbiddenChars(input); | |
return input; | |
} | |
public static string FilterForbiddenChars(string input) | |
{ | |
var forbiddenChars = new string[] { "@", ",", ".", ";", "'", "&", "$", "{", "}" };//to extend | |
foreach (var f in forbiddenChars) | |
{ | |
input = input.Replace(f, string.Empty); | |
} | |
return input; | |
} | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
var input = FormInputHelper.FilterName(textBox1.Text); | |
label1.Text = input; | |
} | |
private void textBox1_TextChanged(object sender, EventArgs e) | |
{ | |
} | |
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) | |
{ | |
if (char.IsLetter(e.KeyChar) || char.IsControl(e.KeyChar) || char.IsPunctuation(e.KeyChar)) | |
{ | |
return; | |
} | |
e.Handled = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment