Solved

How to check for valid text input?

Posted on 1998-08-22
2
188 Views
Last Modified: 2010-03-04
Can someone help me with a Perl code to check for:

1. Valid text input (e.g. a person's name)

2. Valid text and numbers input (e.g an address)

I would like to use this in my form-processor. Thanks!
0
Comment
Question by:zgee
2 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
1. a person's name may have numbers
2. an address may have no numbers

Unless the address is known to be in a specific area with specific rules for what is valis and what is not,
I don't see how you could check this in any language.
0
 
LVL 4

Accepted Solution

by:
mitek earned 10 total points
Comment Utility
of course, it can be checked, and in any language
one way to do that in perl would be:

if ($name =~ /^[\w\'- ]+$/) {
  # valid name. it contains only letters, spaces, dashes and quotes (like, o'donnel)
}

if ($address =~ /^[\w\d\'\"- ]+$/) {
  # valid address. it contains letters, digits, spaces, dashes, single and double quotes
}

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now