NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
[System.Serializable]
public class RegisteredUserDetails
{
public string userName, phoneNumber, email;
public int score;

public RegisteredUserDetails()
{
userName = phoneNumber = email ="";
score = 0;
}
}

public enum RegistrationResponseType { registered, alreadyExists, networkError, emptyData };

public class CricketUtility : MonoBehaviour {

public static RegisteredUserDetails GetUserDetailsOnCheckURL(string serverResponse)
{
serverResponse = "5,PPKK155JJ,998877,[email protected], 501";
// serverResponse = "No user found";

// check if valid response

// if valid response, initiate data

RegisteredUserDetails RD = new RegisteredUserDetails();

string[] words = Regex.Split(serverResponse, ",");
// LeaderboardEntry ld_entry = new LeaderboardEntry();

/**
* We need 3 elements to be accessed
**/
//if (words.Length > 2)
//{
bool is_data_valid = true;

if (words.Length > 3)
{
RD.userName = words[1];
RD.phoneNumber = words[2];
RD.email = words[3];

/**
* Check if name contains number, it will be invalid
**/



if (Regex.Matches(RD.userName, "\d").Count > 0)
{
Debug.Log("name contains number!!" + Regex.Matches(RD.userName, "\d").Count);
is_data_valid = false;
}

if (Regex.Matches(RD.phoneNumber, "^[0-9]*$").Count == 0)
{
Debug.Log("Phone No not valid!!");
is_data_valid = false;
}

if (!Int32.TryParse(words[4].ToString(), out RD.score))
{
Debug.Log("score is not an integer");
is_data_valid = false;
}

if (Regex.Matches(RD.email, @"A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*.)+[a-z]{2,4}z").Count == 0)
{
Debug.Log("Email is not valid!!");
is_data_valid = false;
}

}

if (serverResponse.Contains("No user found"))
{
Debug.Log("User Not found");
is_data_valid = false;
}

if (is_data_valid)
{
return RD;

}
else
{
return null;
}

// else return null

//return new RegisteredUserDetails();
}

public static RegisteredUserDetails GetUserDetailsOnRegistrationURL(string serverResponse, ref RegistrationResponseType responseType)
{
serverResponse = "5,PPKKJJ,998877,[email protected], 501";
//serverResponse = "User exists!!n5,PPKKJJ,998877,[email protected], 501";
// serverResponse = "No user found";

// check if valid response

// if valid response, initiate data

RegisteredUserDetails RD = new RegisteredUserDetails();
string[] sentences = new string[3];
string[] words = new string[7];
bool is_data_valid = true;
/**
* check if user already exists
**/
if (serverResponse.Contains("User exists!!"))
{
Debug.Log("user already exists");
responseType = RegistrationResponseType.alreadyExists;
sentences = Regex.Split(serverResponse, "n");

words = Regex.Split(sentences[1], ",");
}
else if (serverResponse == null || serverResponse == "")
{
responseType = RegistrationResponseType.emptyData;
is_data_valid = false;
}
else // registration successful
{
Debug.Log("registration successfull");
responseType = RegistrationResponseType.registered;
words = Regex.Split(serverResponse, ",");
}


// LeaderboardEntry ld_entry = new LeaderboardEntry();

/**
* We need 3 elements to be accessed
**/
//if (words.Length > 2)
//{


/**
* Check if data is still valid, words contains strigns
**/
if (is_data_valid)
{
RD.userName = words[1];
RD.phoneNumber = words[2];
RD.email = words[3];

/**
* Check if name contains number, it will be invalid
**/



if (Regex.Matches(RD.userName, "\d").Count > 0)
{
Debug.Log("name contains number!!" + Regex.Matches(RD.userName, "\d").Count);
is_data_valid = false;
}

if (Regex.Matches(RD.phoneNumber, "^[0-9]*$").Count == 0)
{
Debug.Log("Phone No not valid!!");
is_data_valid = false;
}

if (!Int32.TryParse(words[4].ToString(), out RD.score))
{
Debug.Log("score is not an integer");
is_data_valid = false;
}

if (Regex.Matches(RD.email, @"A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*.)+[a-z]{2,4}z").Count == 0)
{
Debug.Log("Email is not valid!!");
is_data_valid = false;
}

} // end of check for word

if (is_data_valid)
{
Debug.Log("user name" + RD.userName);
return RD;

}
else
{
return null;
}
}

public RegistrationResponseType response = RegistrationResponseType.alreadyExists;
// Use this for initialization
void Start () {
GetUserDetailsOnCheckURL(null);
GetUserDetailsOnRegistrationURL(null, ref response);
Debug.Log("response is: " + response);
}

// Update is called once per frame
void Update () {

}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.