Hey so I’m trying to to create a textbox where you can only type Numbers and letters. How can I do this efficiently? Thanks, Sorry for a short post.
Use TextBox:GetPropertyChangedSignal('Text')
.
TextBox:GetPropertyChangedSignal('Text'):Connect(function() --// every time the text will change, it will filter the punctuation characters
TextBox.Text = TextBox.Text:gsub('%p+', '');
);
Patterns you can filter. I used %p
which stands for punctuation characters
.
2 Likes
why is the plus needed? I am trying to make it only allow lowercase letters so i wanna know what the + means
More info about String Patterns you can find here.
Here’s the explanation for the plus. If you don’t use that plus, it will only match one word/character.
Edit: in our case, it’s not needed, you’re right. However, if you want to match more complex strings, you have to use it (in most cases).
If you want to make it only lowercase, add a :lower()
.
TextBox.Text = TextBox.Text:lower():gsub('%p+', '');